﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23922	Quoting problem in RequestFactory	Berker Peksag	Berker Peksag	"I was trying to convert middleware tests to use `RequestFactory`. I've converted all tests easily except `CommonMiddlewareTest.test_append_slash_quoted`:

{{{#!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"	Bug	closed	Testing framework	dev	Normal	invalid		Berker Peksag	Accepted	1	0	0	0	0	0
