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 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
13 changes: 7 additions & 6 deletions src/hyperlink/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def _encode_userinfo_part(text, maximal=True):
def register_scheme(
text, uses_netloc=True, default_port=None, query_plus_is_space=True
):
# type: (Text, bool, Optional[int], bool) -> None
# type: (Text, bool, Optional[Union[int, str]], bool) -> None
"""Registers new scheme information, resulting in correct port and
slash behavior from the URL object. There are dozens of standard
schemes preregistered, so this function is mostly meant for
Expand All @@ -501,11 +501,12 @@ def register_scheme(
"""
text = text.lower()
if default_port is not None:
try:
default_port = str(default_port)
if all(d in "0123456789" for d in default_port):
default_port = int(default_port)
except (ValueError, TypeError):
else:
raise ValueError(
"default_port expected integer or None, not %r"
"default_port expected nonnegative integer, numeric string, or None, not %r"
% (default_port,)
)

Expand Down Expand Up @@ -1407,9 +1408,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 all(d in "0123456789" for d in default_port)
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