Skip to content

Commit 2ca4b01

Browse files
authored
Reject port numbers that aren't composed only of ASCII digits
1 parent 1640734 commit 2ca4b01

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/rfc3986/parseresult.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ def authority_from(reference, strict):
467467
)
468468

469469
if port:
470-
try:
470+
if port.isascii() and port.isdigit():
471471
port = int(port)
472-
except ValueError:
472+
else:
473473
raise exceptions.InvalidPort(port)
474474
return userinfo, host, port

tests/test_parseresult.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from rfc3986 import exceptions
1919
from rfc3986 import parseresult as pr
2020

21-
INVALID_PORTS = ["443:80", "443:80:443", "abcdef", "port", "43port"]
21+
INVALID_PORTS = ["443:80", "443:80:443", "abcdef", "port", "43port", " 1", "1 ", "𖭖", "-1", " 1", "1_1"]
2222

2323
SNOWMAN = b"\xe2\x98\x83"
2424
SNOWMAN_IDNA_HOST = "http://xn--n3h.com"

0 commit comments

Comments
 (0)