Skip to content

Commit 37720c9

Browse files
committed
CVE-2023-24329 Change subtest to be part of loop instead
Because Python2 doesn't have subtests.
1 parent e4ce644 commit 37720c9

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

Lib/test/test_urlparse.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@
99
import unittest
1010
import urlparse
1111

12+
# Add ability to run sub-tests
13+
def sub_test(param_list):
14+
"""Decorates a test case to run it as a set of subtests."""
15+
16+
def decorator(f):
17+
18+
@functools.wraps(f)
19+
def wrapped(self):
20+
for param in param_list:
21+
with self.subTest(**param):
22+
f(self, **param)
23+
24+
return wrapped
25+
26+
return decorator
27+
28+
1229
RFC1808_BASE = "http://a/b/c/d;p?q#f"
1330
RFC2396_BASE = "http://a/b/c/d;p?q"
1431
RFC3986_BASE = 'http://a/b/c/d;p?q'
@@ -667,19 +684,18 @@ def test_attributes_bad_port(self):
667684
for bytes in (False, True):
668685
for parse in (urlparse.urlsplit, urlparse.urlparse):
669686
for port in ("foo", "1.5", "-1", "0x10", "-0", "1_1", " 1", "1 ", "६"):
670-
with self.subTest(bytes=bytes, parse=parse, port=port):
671-
netloc = "www.example.net:" + port
672-
url = "http://" + netloc + "/"
673-
if bytes:
674-
if netloc.isascii() and port.isascii():
675-
netloc = netloc.encode("ascii")
676-
url = url.encode("ascii")
677-
else:
678-
continue
679-
p = parse(url)
680-
self.assertEqual(p.netloc, netloc)
681-
with self.assertRaises(ValueError):
682-
p.port
687+
netloc = "www.example.net:" + port
688+
url = "http://" + netloc + "/"
689+
if bytes:
690+
if netloc.isascii() and port.isascii():
691+
netloc = netloc.encode("ascii")
692+
url = url.encode("ascii")
693+
else:
694+
continue
695+
p = parse(url)
696+
self.assertEqual(p.netloc, netloc)
697+
with self.assertRaises(ValueError):
698+
p.port
683699

684700
def test_attributes_without_netloc(self):
685701
# This example is straight from RFC 3261. It looks like it

0 commit comments

Comments
 (0)