Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ def _encode(data, name='data'):

def _strip_ipv6_iface(enc_name: bytes) -> bytes:
"""Remove interface scope from IPv6 address."""
enc_name, percent, _ = enc_name.partition(b"%")
if percent:
assert enc_name.startswith(b'['), enc_name
enc_name += b']'
return enc_name
before, percent, after = enc_name.partition(b"%")
if not percent or not before.startswith(b'['):
# No '%' in the input, or it's not a bracketed IPv6 literal, so
# this isn't an IPv6 zone id -- e.g. RFC 3986 percent-encoding
# elsewhere in the netloc, most plausibly in userinfo (required
# whenever a username/password contains '@', ':', '/', or '%').
# Leave it untouched rather than assuming the '%' we happened to
# find is a zone separator.
return enc_name
return before + b']'

class HTTPMessage(email.message.Message):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :exc:`AssertionError` in :meth:`http.client.HTTPConnection.putrequest`
when an absolute-URL request's netloc contains RFC 3986 percent-encoding

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


outside of an IPv6 zone identifier, such as percent-encoded userinfo.
Loading