From bfdd54e815334dbfd0f65ec6559a711b4973a6eb Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 8 Jun 2022 08:31:05 +0000 Subject: [PATCH] [FIX] http_routing: support invalid ipv6 URL opw-2870792 closes odoo/odoo#93138 X-original-commit: 4e052a387885890d9b0950fae825624b7f7a3f2b Signed-off-by: Romain Derie (rde) --- addons/http_routing/models/ir_http.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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