diff options
author | Vlastimil Zíma <vlastimil.zima@nic.cz> | 2020-07-08 11:05:34 +0200 |
---|---|---|
committer | Vlastimil Zíma <vlastimil.zima@nic.cz> | 2020-07-08 11:05:34 +0200 |
commit | 7d26c7fd7af64dfafc6e71cfc29e003131616d9d (patch) | |
tree | 7120391e2a2baa057f71cd0158e159e8a07ed1d7 | |
parent | 4b0cbbf37ee2f7a672d9984c175334ed8de5e4d0 (diff) | |
parent | aba0333707d56102096e55f3caaddc56b3390528 (diff) | |
download | openid-7d26c7fd7af64dfafc6e71cfc29e003131616d9d.tar.gz |
Merge branch 'fix-urinorm-path'
-rw-r--r-- | openid/test/test_urinorm.py | 8 | ||||
-rw-r--r-- | openid/urinorm.py | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/openid/test/test_urinorm.py b/openid/test/test_urinorm.py index 2c7aa0c..53debfe 100644 --- a/openid/test/test_urinorm.py +++ b/openid/test/test_urinorm.py @@ -71,11 +71,17 @@ class UrinormTest(unittest.TestCase): self.assertEqual(urinorm('http://example.com/Λ'), 'http://example.com/%CE%9B') def test_path_capitalize_percent_encoding(self): - self.assertEqual(urinorm('http://example.com/foo%2cbar'), 'http://example.com/foo%2Cbar') + self.assertEqual(urinorm('http://example.com/foo%3abar'), 'http://example.com/foo%3Abar') def test_path_percent_decode_unreserved(self): self.assertEqual(urinorm('http://example.com/foo%2Dbar%2dbaz'), 'http://example.com/foo-bar-baz') + def test_path_keep_sub_delims(self): + self.assertEqual(urinorm('http://example.com/foo+!bar'), 'http://example.com/foo+!bar') + + def test_path_percent_decode_sub_delims(self): + self.assertEqual(urinorm('http://example.com/foo%2B%21bar'), 'http://example.com/foo+!bar') + def test_illegal_characters(self): six.assertRaisesRegex(self, ValueError, 'Illegal characters in URI', urinorm, 'http://<illegal>.com/') diff --git a/openid/urinorm.py b/openid/urinorm.py index 6a5a588..9678741 100644 --- a/openid/urinorm.py +++ b/openid/urinorm.py @@ -122,10 +122,10 @@ def urinorm(uri): # This is hackish. `unquote` and `quote` requires `str` in both py27 and py3+. if isinstance(path, str): # Python 3 branch - path = quote(unquote(path)) + path = quote(unquote(path), safe='/' + SUB_DELIMS) else: # Python 2 branch - path = quote(unquote(path.encode('utf-8'))).decode('utf-8') + path = quote(unquote(path.encode('utf-8')), safe=('/' + SUB_DELIMS).encode('utf-8')).decode('utf-8') path = remove_dot_segments(path) if not path: |