diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 9ba68b5e0d5..b2a0ae131f3 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -518,6 +518,11 @@ class IrHttp(models.AbstractModel): string. This act as a light redirection, it does not return a 3xx responses to the browser but still change the current URL. """ + # WSGI encoding dance https://peps.python.org/pep-3333/#unicode-issues + if isinstance(path, str): + path = path.encode('utf-8') + path = path.decode('latin1', 'replace') + if query_string is None: query_string = request.httprequest.environ['QUERY_STRING'] diff --git a/addons/website/tests/test_lang_url.py b/addons/website/tests/test_lang_url.py index b4a49b1db20..1daad1e52eb 100644 --- a/addons/website/tests/test_lang_url.py +++ b/addons/website/tests/test_lang_url.py @@ -99,6 +99,13 @@ class TestLangUrl(HttpCase): [anchor] = doc.xpath('//a[@id="foo"]') self.assertEqual(anchor.get('href'), 'http://]', 'The invalid IP URL must be left untouched') + def test_06_reroute_unicode(self): + res = self.url_open('/fr/привет') + self.assertEqual(res.status_code, 404, "Rerouting didn't crash because of unicode path") + + res = self.url_open('/fr/path?привет=1') + self.assertEqual(res.status_code, 404, "Rerouting didn't crash because of unicode query-string") + @tagged('-at_install', 'post_install') class TestControllerRedirect(TestLangUrl):