[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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user