We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
validators.subauthority_component_is_valid
int(...)
1 parent fadc962 commit c923049Copy full SHA for c923049
src/rfc3986/validators.py
@@ -437,16 +437,16 @@ def subauthority_component_is_valid(
437
elif component != "port":
438
return True
439
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
+ port = subauthority_dict["port"]
+
+ if port is None:
447
448
449
- 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
450
451
452
def ensure_components_are_valid(
0 commit comments