Skip to content
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

Fix non-numeric port number bug (addresses #180) #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/hyperlink/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ def register_scheme(
"""
text = text.lower()
if default_port is not None:
try:
if isinstance(default_port, int) or (isinstance(default_port, str) and default_port.isdigit() and default_port.isascii()):
kenballus marked this conversation as resolved.
Show resolved Hide resolved
default_port = int(default_port)
except (ValueError, TypeError):
else:
raise ValueError(
"default_port expected integer or None, not %r"
% (default_port,)
Expand Down Expand Up @@ -1407,9 +1407,9 @@ def from_text(cls, text):
host = au_gs["ipv6_host"] or au_gs["plain_host"]
port = au_gs["port"]
if port is not None:
try:
if port.isdigit() and port.isascii():
port = int(port) # type: ignore[assignment] # FIXME, see below
except ValueError:
else:
if not port: # TODO: excessive?
raise URLParseError("port must not be empty: %r" % au_text)
raise URLParseError("expected integer for port, not %r" % port)
Expand Down