From 5945e8e4e353ff45657e59b600464254839bd5c9 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 19 Nov 2021 13:34:06 +0000 Subject: [PATCH] [FIX] http_routing: don't remove trailing / during redirect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, since we promote the use of route without trailing / for best SEO (fee0113), we remove the trailing / during a redirect to avoid an extra request. Unfortunately, it will break some route with trailing / in case of multi lang. So we remove this optimization, it will increase potentially number of http request before to get the final url, but it will allow to continue to support trailing slash in v15. This commit partially revert the commit ae35117 closes odoo/odoo#80191 X-original-commit: 84d2f5b57ccf3dbcefebdbc795ab1872bc1504b9 Signed-off-by: Romain Derie (rde) Signed-off-by: Jérémy Kersten (jke) --- addons/http_routing/models/ir_http.py | 6 +----- addons/website/tests/test_lang_url.py | 2 +- addons/website/tests/test_qweb.py | 6 +++--- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index daa76e43b2a..1eceb390587 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -167,11 +167,7 @@ def url_lang(path_or_uri, lang_code=None): elif lang_url_code != default_lg.url_code or force_lang: ps.insert(1, lang_url_code) - # remove trailing / - # ['', fr', ''] => /fr/ instead of /fr - if ps[-1] == '': - ps.pop(-1) - location = (u'/'.join(ps) or u'/') + sep + qs + location = u'/'.join(ps) + sep + qs return location diff --git a/addons/website/tests/test_lang_url.py b/addons/website/tests/test_lang_url.py index 98a8de4b974..bd021fd66a9 100644 --- a/addons/website/tests/test_lang_url.py +++ b/addons/website/tests/test_lang_url.py @@ -22,7 +22,7 @@ class TestLangUrl(HttpCase): def test_01_url_lang(self): with MockRequest(self.env, website=self.website): - self.assertEqual(url_lang('', '[lang]'), '/[lang]/hello', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.") + self.assertEqual(url_lang('', '[lang]'), '/[lang]/hello/', "`[lang]` is used to be replaced in the url_return after installing a language, it should not be replaced or removed.") def test_02_url_redirect(self): url = '/fr_WHATEVER/contactus' diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py index 8c1dc4d82af..08a3c966cdc 100644 --- a/addons/website/tests/test_qweb.py +++ b/addons/website/tests/test_qweb.py @@ -140,14 +140,14 @@ class TestQwebProcessAtt(TransactionCase): with MockRequest(self.env, website=self.website): self._test_att('/', {'href': '/'}) self._test_att('/en/', {'href': '/'}) - self._test_att('/fr/', {'href': '/fr'}) + self._test_att('/fr/', {'href': '/fr/'}) self._test_att('/fr', {'href': '/fr'}) def test_process_att_with_request_lang(self): with MockRequest(self.env, website=self.website, context={'lang': 'fr_FR'}): - self._test_att('/', {'href': '/fr'}) + self._test_att('/', {'href': '/fr/'}) self._test_att('/en/', {'href': '/'}) - self._test_att('/fr/', {'href': '/fr'}) + self._test_att('/fr/', {'href': '/fr/'}) self._test_att('/fr', {'href': '/fr'}) def test_process_att_matching_cdn_and_lang(self):