Skip to content

Commit c923049

Browse files
Change how port is determined/validated in validators.subauthority_component_is_valid to avoid testing via int(...).
- Also makes the linters and type-checker happier.
1 parent fadc962 commit c923049

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/rfc3986/validators.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -437,16 +437,16 @@ def subauthority_component_is_valid(
437437
elif component != "port":
438438
return True
439439

440-
try:
441-
# fmt: off
442-
port = int(subauthority_dict["port"]) # pyright: ignore[reportArgumentType] # noqa: E501 # Guarded by "except TypeError".
443-
# fmt: on
444-
except TypeError:
445-
# If the port wasn't provided it'll be None and int(None) raises a
446-
# TypeError
440+
port = subauthority_dict["port"]
441+
442+
if port is None:
447443
return True
448444

449-
return 0 <= port <= 65535
445+
# We know it has to have fewer than 6 digits if it exists.
446+
if not (port.isdigit() and len(port) < 6):
447+
return False
448+
449+
return 0 <= int(port) <= 65535
450450

451451

452452
def ensure_components_are_valid(

0 commit comments

Comments
 (0)