diff options
author | Gregory P. Smith <greg@krypto.org> | 2019-05-01 20:39:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-01 20:39:21 (GMT) |
commit | b7378d77289c911ca6a0c0afaf513879002df7d5 (patch) | |
tree | 1102bd7d38307fbaf3d32ee3299ee43a1a64b775 /Lib/test/test_urllib.py | |
parent | e1d5dd645d5f59867cb0ad63179110f310cbca89 (diff) | |
download | cpython-b7378d77289c911ca6a0c0afaf513879002df7d5.zip cpython-b7378d77289c911ca6a0c0afaf513879002df7d5.tar.gz cpython-b7378d77289c911ca6a0c0afaf513879002df7d5.tar.bz2 |
bpo-30458: Use InvalidURL instead of ValueError. (GH-13044)
Use http.client.InvalidURL instead of ValueError as the new error case's exception.
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r-- | Lib/test/test_urllib.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index c5b23f9..7214492 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -343,11 +343,12 @@ class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): # calls urllib.parse.quote() on the URL which makes all of the # above attempts at injection within the url _path_ safe. escaped_char_repr = repr(char).replace('\\', r'\\') + InvalidURL = http.client.InvalidURL with self.assertRaisesRegex( - ValueError, f"contain control.*{escaped_char_repr}"): + InvalidURL, f"contain control.*{escaped_char_repr}"): urllib.request.urlopen(f"http:{schemeless_url}") with self.assertRaisesRegex( - ValueError, f"contain control.*{escaped_char_repr}"): + InvalidURL, f"contain control.*{escaped_char_repr}"): urllib.request.urlopen(f"https:{schemeless_url}") # This code path quotes the URL so there is no injection. resp = urlopen(f"http:{schemeless_url}") @@ -367,10 +368,11 @@ class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin, FakeFTPMixin): # urlopen uses FancyURLOpener which goes via a codepath that # calls urllib.parse.quote() on the URL which makes all of the # above attempts at injection within the url _path_ safe. + InvalidURL = http.client.InvalidURL with self.assertRaisesRegex( - ValueError, r"contain control.*\\r.*(found at least . .)"): + InvalidURL, r"contain control.*\\r.*(found at least . .)"): urllib.request.urlopen(f"http:{schemeless_url}") - with self.assertRaisesRegex(ValueError, r"contain control.*\\n"): + with self.assertRaisesRegex(InvalidURL, r"contain control.*\\n"): urllib.request.urlopen(f"https:{schemeless_url}") # This code path quotes the URL so there is no injection. resp = urlopen(f"http:{schemeless_url}") |