Skip to content

gh-96035: Make urllib.parse.urlparse reject non-numeric ports #98273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions Lib/urllib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def port(self):
port = self._hostinfo[1]
if port is not None:
try:
if not port.isdigit():
raise ValueError(f"Port {port!r} contains non-numeric character(s)")
port = int(port, 10)
except ValueError:
message = f'Port could not be cast to integer value as {port!r}'
Expand Down Expand Up @@ -1139,6 +1141,8 @@ def _splitnport(host, defport=-1):
host = port
elif port:
try:
if not port.isdigit():
raise ValueError(f"Port {port!r} contains non-numeric character(s)")
nport = int(port)
except ValueError:
nport = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes bug in urllib.parse.urlparse that causes certain port numbers
containing whitespace, underscores, or plus and minus signs to be
incorrectly accepted.