diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 0b37ce8c756..9ebec6dca62 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -135,7 +135,7 @@ def unslug_url(s): def url_lang(path_or_uri, lang_code=None): ''' Given a relative URL, make it absolute and add the required lang or remove useless lang. - Nothing will be done for absolute URL. + Nothing will be done for absolute or invalid URL. If there is only one language installed, the lang will not be handled unless forced with `lang` parameter. @@ -145,9 +145,13 @@ def url_lang(path_or_uri, lang_code=None): Lang = request.env['res.lang'] location = pycompat.to_text(path_or_uri).strip() force_lang = lang_code is not None - url = werkzeug.urls.url_parse(location) + try: + url = werkzeug.urls.url_parse(location) + except ValueError: + # e.g. Invalid IPv6 URL, `werkzeug.urls.url_parse('http://]')` + url = False # relative URL with either a path or a force_lang - if not url.netloc and not url.scheme and (url.path or force_lang): + if url and not url.netloc and not url.scheme and (url.path or force_lang): location = werkzeug.urls.url_join(request.httprequest.path, location) lang_url_codes = [url_code for _, url_code, *_ in Lang.get_available()] lang_code = pycompat.to_text(lang_code or request.context['lang']) @@ -174,7 +178,7 @@ def url_lang(path_or_uri, lang_code=None): def url_for(url_from, lang_code=None, no_rewrite=False): ''' Return the url with the rewriting applied. - Nothing will be done for absolute URL, or short URL from 1 char. + Nothing will be done for absolute URL, invalid URL, or short URL from 1 char. :param url_from: The URL to convert. :param lang_code: Must be the lang `code`. It could also be something