Skip to content

Commit

Permalink
Change how port is determined/validated in `validators.subauthority_c…
Browse files Browse the repository at this point in the history
…omponent_is_valid` to avoid testing via `int(...)`.

- Also makes the linters and type-checker happier.
  • Loading branch information
Sachaa-Thanasius committed Jun 22, 2024
1 parent fadc962 commit c923049
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/rfc3986/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,16 @@ def subauthority_component_is_valid(
elif component != "port":
return True

try:
# fmt: off
port = int(subauthority_dict["port"]) # pyright: ignore[reportArgumentType] # noqa: E501 # Guarded by "except TypeError".
# fmt: on
except TypeError:
# If the port wasn't provided it'll be None and int(None) raises a
# TypeError
port = subauthority_dict["port"]

if port is None:
return True

return 0 <= port <= 65535
# We know it has to have fewer than 6 digits if it exists.
if not (port.isdigit() and len(port) < 6):
return False

return 0 <= int(port) <= 65535


def ensure_components_are_valid(
Expand Down

0 comments on commit c923049

Please sign in to comment.