summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urlparse.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-06-11 10:45:35 (GMT)
committerGitHub <noreply@github.com>2019-06-11 10:45:35 (GMT)
commit2b578479b96aa3deeeb8bac313a02b5cf3cb1aff (patch)
tree2ac4c481cc985580dd6a34ca21a5614a886a5741 /Lib/test/test_urlparse.py
parent99b5c940d3471e0ed6579771d94e7342d7c733e0 (diff)
downloadcpython-2b578479b96aa3deeeb8bac313a02b5cf3cb1aff.zip
cpython-2b578479b96aa3deeeb8bac313a02b5cf3cb1aff.tar.gz
cpython-2b578479b96aa3deeeb8bac313a02b5cf3cb1aff.tar.bz2
[2.7] bpo-36742: Fix urlparse.urlsplit() error message for Unicode URL (GH-13937)
If urlparse.urlsplit() detects an invalid netloc according to NFKC normalization, the error message type is now str rather than unicode, and use repr() to format the URL, to prevent <exception str() failed> when display the error message.
Diffstat (limited to 'Lib/test/test_urlparse.py')
-rw-r--r--Lib/test/test_urlparse.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index 857ed96..86c4a05 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -656,6 +656,15 @@ class UrlParseTestCase(unittest.TestCase):
with self.assertRaises(ValueError):
urlparse.urlsplit(url)
+ # check error message: invalid netloc must be formated with repr()
+ # to get an ASCII error message
+ with self.assertRaises(ValueError) as cm:
+ urlparse.urlsplit(u'http://example.com\uFF03@bing.com')
+ self.assertEqual(str(cm.exception),
+ "netloc u'example.com\\uff03@bing.com' contains invalid characters "
+ "under NFKC normalization")
+ self.assertIsInstance(cm.exception.args[0], str)
+
def test_main():
test_support.run_unittest(UrlParseTestCase)