From c70842e2543a5e366044edcc5f450d48238f0eba Mon Sep 17 00:00:00 2001 From: Huy Le Date: Sat, 19 Nov 2022 03:53:09 +0000 Subject: [PATCH] [FIX] http_routing: remove trailing `/` Currently, the character `/` appears at the end of the url of the language dropdown on the home page e.g. /en/, /fr/. This will cause one more redirect when performing the language change. Indeed, this error is only encountered with path = / Please try the following `url_lang('/', 'en_US')` => /en/ After this fix, the trailing `/` will be removed when using the func `url_lang` e.g. `url_lang('', 'en_US')` => /en, this means that the language switching links on the homepage no longer redirect redundantly again. closes odoo/odoo#106109 Signed-off-by: Romain Derie (rde) --- addons/http_routing/models/ir_http.py | 3 +++ addons/website/tests/test_qweb.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 759c2af20af..657895dc823 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -167,6 +167,9 @@ def url_lang(path_or_uri, lang_code=None): # Insert the context language or the provided language elif lang_url_code != default_lg.url_code or force_lang: ps.insert(1, lang_url_code) + # Remove the last empty string to avoid trailing / after joining + if ps[-1] == '': + ps.pop(-1) location = u'/'.join(ps) + sep + qs return location diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py index e58246174d0..ae2848c5c67 100644 --- a/addons/website/tests/test_qweb.py +++ b/addons/website/tests/test_qweb.py @@ -77,7 +77,7 @@ class TestQwebProcessAtt(TransactionCase): 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'})