{{{#!python
@override_settings(APPEND_SLASH=True)
def test_append_slash_quoted(self):
"""
Tests that URLs which require quoting are redirected to their
slash
version ok.
"""
request = self._get_request('needsquoting#')
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(
r.url,
'http://testserver/needsquoting%23/')
}}}
https://github.com/django/django/blob/master/tests/middleware/tests.py#L94
The `urlparse` call in the `RequestFactory.generic` method swallows `#` in
the URL. The test is passing with a plain `HttpRequest` object.
Here is a try to fix this problem:
https://github.com/berkerpeksag/django/compare/use-requestfactory
An alternative fix would be to wrap `path` with `quote(path, safe=b"...")`
or with `django.utils.encoding.escape_uri_path` in
`RequestFactory.generic`:
https://github.com/django/django/blob/master/django/test/client.py#L351
--
Ticket URL: <https://code.djangoproject.com/ticket/23922>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/23922#comment:1>
* owner: nobody => berkerpeksag
* status: new => assigned
* has_patch: 0 => 1
Comment:
https://github.com/django/django/pull/3645
--
Ticket URL: <https://code.djangoproject.com/ticket/23922#comment:2>
* needs_better_patch: 0 => 1
Comment:
Question about the implementation left on the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/23922#comment:3>
Comment (by timgraham):
On further investigation, I think we can simply use the urlencoded version
of # when updating that test to use `RequestFactory` like this:
`rf.get('/needsquoting%23')`. The test passes and works as a regression
test as originally intended if I remove `urlquote` from
`urlquote(new_url[1])` in `CommonMiddleware`.
--
Ticket URL: <https://code.djangoproject.com/ticket/23922#comment:4>
* status: assigned => closed
* needs_better_patch: 1 => 0
* resolution: => invalid
Comment:
Thanks. I agree with your analysis. I'll convert my branch to a pull
request and will close [https://github.com/django/django/pull/3645 PR
#3645].
--
Ticket URL: <https://code.djangoproject.com/ticket/23922#comment:5>