From 1bf9367c6f8d35d6e06de6cc0645b9315b3bdc15 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 25 Jun 2021 15:49:55 +0000 Subject: [PATCH] [FIX] http_routing: fix url_for with querystring before this commit url_for('/fr?a=b') -> /fr/fr?a=b because /fr?a=b not in ['fr', 'en'] Now we split query string before to check that first path is a lang --- addons/http_routing/models/ir_http.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index c76e9e749cc..a64e3639565 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -152,9 +152,9 @@ def url_lang(path_or_uri, lang_code=None): lang_code = pycompat.to_text(lang_code or request.context['lang']) lang_url_code = Lang._lang_code_to_urlcode(lang_code) lang_url_code = lang_url_code if lang_url_code in lang_url_codes else lang_code - if (len(lang_url_codes) > 1 or force_lang) and is_multilang_url(location, lang_url_codes): - ps = location.split(u'/') + loc, sep, qs = location.partition('?') + ps = loc.split(u'/') default_lg = request.env['ir.http']._get_default_lang() if ps[1] in lang_url_codes: # Replace the language only if we explicitly provide a language to url_for @@ -166,7 +166,7 @@ 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) - location = u'/'.join(ps) + location = u'/'.join(ps) + sep + qs return location