Skip to content

Commit 850671f

Browse files
authored
Merge pull request #169 from Matoking/quote_fix
Use requests to quote URLs
2 parents cb8084a + 77f1a1f commit 850671f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
fixes:
3+
- As part of 1.9.0 we started quoting unsafe URL characters. This was done incorrectly that meant we requoted existing quoted strings. Fixes #170.

requests_mock/adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import weakref
1414

1515
from requests.adapters import BaseAdapter
16+
from requests.utils import requote_uri
1617
import six
1718
from six.moves.urllib import parse as urlparse
1819

@@ -102,7 +103,7 @@ def __init__(self, method, url, responses, complete_qs, request_headers,
102103
url_parts = urlparse.urlparse(url)
103104
self._scheme = url_parts.scheme.lower()
104105
self._netloc = url_parts.netloc.lower()
105-
self._path = urlparse.quote(url_parts.path or '/')
106+
self._path = requote_uri(url_parts.path or '/')
106107
self._query = url_parts.query
107108

108109
if not case_sensitive:

tests/test_matcher.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ def test_url_matching(self):
141141
'http://www.test.com/abc')
142142
self.assertMatchBoth('http://www.test.com:5000/abc',
143143
'http://www.test.com:5000/abc')
144-
self.assertMatchBoth('http://www.test.com/a string%url',
145-
'http://www.test.com/a string%url')
146-
147144
self.assertNoMatchBoth('https://www.test.com',
148145
'http://www.test.com')
149146
self.assertNoMatchBoth('http://www.test.com/abc',
@@ -161,6 +158,14 @@ def test_url_matching(self):
161158
self.assertNoMatchBoth('http://test.com/abc/',
162159
'http://www.test.com:5000/abc')
163160

161+
def test_quotation(self):
162+
self.assertMatchBoth('http://www.test.com/a string%url',
163+
'http://www.test.com/a string%url')
164+
self.assertMatchBoth('http://www.test.com/ABC 123',
165+
'http://www.test.com/ABC%20123')
166+
self.assertMatchBoth('http://www.test.com/[email protected]',
167+
'http://www.test.com/[email protected]')
168+
164169
def test_subset_match(self):
165170
self.assertMatch('/path', 'http://www.test.com/path')
166171
self.assertMatch('/path', 'http://www.test.com/path')

0 commit comments

Comments
 (0)