Skip to content

Commit 2f8e798

Browse files
committed
CVE-2023-24329 Rejig the tests to handle that we strip more bad characters now
1 parent 39590e8 commit 2f8e798

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Lib/test/test_urlparse.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,26 +679,34 @@ def test_urlsplit_strip_url(self):
679679
self.assertEqual(p.scheme, "https")
680680
self.assertEqual(p.geturl(), "https://www.python.org/")
681681

682-
def test_attributes_bad_port(self):
682+
def test_attributes_bad_port_a(self):
683683
"""Check handling of invalid ports."""
684684
for bytes in (False, True):
685685
for parse in (urlparse.urlsplit, urlparse.urlparse):
686-
# Spaces are stripped now, so they can't cause issues
686+
# Spaces and invalid characters are stripped now, so the missing one's can't cause issues
687687
# for port in ("foo", "1.5", "-1", "0x10", "-0", "1_1", " 1", "1 ", "६"):
688-
for port in ("foo", "1.5", "-1", "0x10", "-0", "1_1", "६"):
688+
for port in ("foo", "1.5", "0x10", "1_1"):
689689
netloc = "www.example.net:" + port
690690
url = "http://" + netloc + "/"
691691
if bytes:
692-
if netloc.isascii() and port.isascii():
693-
netloc = netloc.encode("ascii")
694-
url = url.encode("ascii")
695-
else:
696-
continue
692+
netloc = netloc.encode("ascii")
693+
url = url.encode("ascii")
697694
p = parse(url)
698695
self.assertEqual(p.netloc, netloc)
699696
with self.assertRaises(ValueError):
700697
p.port
701698

699+
def test_attributes_bad_port_b(self):
700+
"""Check handling of invalid ports."""
701+
for parse in (urlparse.urlsplit, urlparse.urlparse):
702+
for port in ("६"):
703+
netloc = "www.example.net:" + port
704+
url = "http://" + netloc + "/"
705+
p = parse(url)
706+
self.assertEqual(p.netloc, netloc)
707+
with self.assertRaises(ValueError):
708+
p.port
709+
702710
def test_attributes_without_netloc(self):
703711
# This example is straight from RFC 3261. It looks like it
704712
# should allow the username, hostname, and port to be filled

0 commit comments

Comments
 (0)