Skip to content
Myr

modifying IDNA encoding check to allow fallback

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by Nate Prewitt · parent 264f5bd · Browse files · 1 file+9 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−3 removed

  • other:+9 added−3 removed

1 file+9 added−3 removed

modified:requests/models.py+9 added-3 removed
28 unmodified lines
29 DecodeError, ReadTimeoutError, ProtocolError, LocationParseError)30from .exceptions import (31 HTTPError, MissingSchema, InvalidURL, ChunkedEncodingError,32 ContentDecodingError, ConnectionError, StreamConsumedError)33from ._internal_utils import to_native_string33from ._internal_utils import to_native_string, unicode_is_ascii34from .utils import (35 guess_filename, get_auth_from_url, requote_uri,36 stream_decode_response_unicode, to_key_val_list, parse_header_links,37 iter_slices, guess_json_utf, super_len, check_header_validity)
326 unmodified lines
364365 if not host:366 raise InvalidURL("Invalid URL %r: No host supplied" % url)367368 # Only want to apply IDNA to the hostname368 # In general, we want to try IDNA encoding every hostname, as that369 # allows users to automatically get the correct behaviour. However,370 # we’re quite strict about IDNA encoding, so certain valid hostnames371 # may fail to encode. On failure, we verify the hostname meets a372 # minimum standard of only containing ASCII characters, and not starting373 # with a wildcard (*), before allowing the unencoded hostname through.374 try:375 host = idna.encode(host, uts46=True).decode('utf-8')376 except (UnicodeError, idna.IDNAError):377 if not unicode_is_ascii(host) or host.startswith(u'*'):372 raise InvalidURL('URL has an invalid label.')378 raise InvalidURL('URL has an invalid label.')379380 # Carefully reconstruct the network location381 netloc = auth or ''382 if netloc:
521 unmodified lines