Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[1.2.X] Fixed #14939: Don't strip ;-parameters from URLs in the test …
…client.

Backport of [15027] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15045 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
andrewgodwin committed Dec 23, 2010
1 parent 6c32577 commit b168c1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 13 additions & 6 deletions django/test/client.py
Expand Up @@ -198,6 +198,13 @@ def _session(self):
return {}
session = property(_session)

def _get_path(self, parsed):
# If there are parameters, add them
if parsed[3]:
return urllib.unquote(parsed[2] + ";" + parsed[3])
else:
return urllib.unquote(parsed[2])

def request(self, **request):
"""
The master request method. Composes the environment dictionary
Expand Down Expand Up @@ -288,7 +295,7 @@ def get(self, path, data={}, follow=False, **extra):
parsed = urlparse(path)
r = {
'CONTENT_TYPE': 'text/html; charset=utf-8',
'PATH_INFO': urllib.unquote(parsed[2]),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'GET',
'wsgi.input': FakePayload('')
Expand Down Expand Up @@ -320,7 +327,7 @@ def post(self, path, data={}, content_type=MULTIPART_CONTENT,
r = {
'CONTENT_LENGTH': len(post_data),
'CONTENT_TYPE': content_type,
'PATH_INFO': urllib.unquote(parsed[2]),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': parsed[4],
'REQUEST_METHOD': 'POST',
'wsgi.input': FakePayload(post_data),
Expand All @@ -339,7 +346,7 @@ def head(self, path, data={}, follow=False, **extra):
parsed = urlparse(path)
r = {
'CONTENT_TYPE': 'text/html; charset=utf-8',
'PATH_INFO': urllib.unquote(parsed[2]),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'HEAD',
'wsgi.input': FakePayload('')
Expand All @@ -357,7 +364,7 @@ def options(self, path, data={}, follow=False, **extra):
"""
parsed = urlparse(path)
r = {
'PATH_INFO': urllib.unquote(parsed[2]),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'OPTIONS',
'wsgi.input': FakePayload('')
Expand Down Expand Up @@ -389,7 +396,7 @@ def put(self, path, data={}, content_type=MULTIPART_CONTENT,
r = {
'CONTENT_LENGTH': len(post_data),
'CONTENT_TYPE': content_type,
'PATH_INFO': urllib.unquote(parsed[2]),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': query_string or parsed[4],
'REQUEST_METHOD': 'PUT',
'wsgi.input': FakePayload(post_data),
Expand All @@ -407,7 +414,7 @@ def delete(self, path, data={}, follow=False, **extra):
"""
parsed = urlparse(path)
r = {
'PATH_INFO': urllib.unquote(parsed[2]),
'PATH_INFO': self._get_path(parsed),
'QUERY_STRING': urlencode(data, doseq=True) or parsed[4],
'REQUEST_METHOD': 'DELETE',
'wsgi.input': FakePayload('')
Expand Down
7 changes: 7 additions & 0 deletions tests/modeltests/test_client/models.py
Expand Up @@ -266,6 +266,13 @@ def test_unknown_page(self):
# Check that the response was a 404
self.assertEqual(response.status_code, 404)

def test_url_parameters(self):
"Make sure that URL ;-parameters are not stripped."
response = self.client.get('/test_client/unknown_view/;some-parameter')

# Check that the path in the response includes it (ignore that it's a 404)
self.assertEqual(response.request['PATH_INFO'], '/test_client/unknown_view/;some-parameter')

def test_view_with_login(self):
"Request a page that is protected with @login_required"

Expand Down

0 comments on commit b168c1b

Please sign in to comment.