diff options
author | shadchin <shadchin@yandex-team.com> | 2025-02-16 15:28:01 +0300 |
---|---|---|
committer | shadchin <shadchin@yandex-team.com> | 2025-02-16 16:03:50 +0300 |
commit | a27b6a96fdc5ca444428ddef4823d0486dcdccb9 (patch) | |
tree | adde5c24d9ea37e1634e7972e27e682a820ab941 /contrib/tools/python3/Lib/urllib/parse.py | |
parent | 7a3958c3c6de324baab9dba4bd4eb808c1b839a6 (diff) | |
download | ydb-a27b6a96fdc5ca444428ddef4823d0486dcdccb9.tar.gz |
Update Python 3 to 3.12.9
commit_hash:c8651982d81e18f18e037fb247cc6ae53c4fa7f1
Diffstat (limited to 'contrib/tools/python3/Lib/urllib/parse.py')
-rw-r--r-- | contrib/tools/python3/Lib/urllib/parse.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/contrib/tools/python3/Lib/urllib/parse.py b/contrib/tools/python3/Lib/urllib/parse.py index 2481595203..c72138a33c 100644 --- a/contrib/tools/python3/Lib/urllib/parse.py +++ b/contrib/tools/python3/Lib/urllib/parse.py @@ -436,6 +436,23 @@ def _checknetloc(netloc): raise ValueError("netloc '" + netloc + "' contains invalid " + "characters under NFKC normalization") +def _check_bracketed_netloc(netloc): + # Note that this function must mirror the splitting + # done in NetlocResultMixins._hostinfo(). + hostname_and_port = netloc.rpartition('@')[2] + before_bracket, have_open_br, bracketed = hostname_and_port.partition('[') + if have_open_br: + # No data is allowed before a bracket. + if before_bracket: + raise ValueError("Invalid IPv6 URL") + hostname, _, port = bracketed.partition(']') + # No data is allowed after the bracket but before the port delimiter. + if port and not port.startswith(":"): + raise ValueError("Invalid IPv6 URL") + else: + hostname, _, port = hostname_and_port.partition(':') + _check_bracketed_host(hostname) + # Valid bracketed hosts are defined in # https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/ def _check_bracketed_host(hostname): @@ -496,8 +513,7 @@ def urlsplit(url, scheme='', allow_fragments=True): (']' in netloc and '[' not in netloc)): raise ValueError("Invalid IPv6 URL") if '[' in netloc and ']' in netloc: - bracketed_host = netloc.partition('[')[2].partition(']')[0] - _check_bracketed_host(bracketed_host) + _check_bracketed_netloc(netloc) if allow_fragments and '#' in url: url, fragment = url.split('#', 1) if '?' in url: |