[FIX] http_routing: support invalid ipv6 URL
opw-2870792 closes odoo/odoo#93138 X-original-commit: 4e052a387885890d9b0950fae825624b7f7a3f2b Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user