Skip to content

Commit

Permalink
Merge pull request #20 from talam/adjust_unsafe_list
Browse files Browse the repository at this point in the history
unescape space in params, query string, and fragments
  • Loading branch information
jehiah authored Aug 5, 2016
2 parents 29dd785 + 95d41b1 commit 197a352
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from distutils.core import setup

# also update in urlnorm.py
version = '1.1.3'
version = '1.1.4'

setup(name='urlnorm',
version=version,
Expand Down
10 changes: 5 additions & 5 deletions test_urlnorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def pytest_generate_tests(metafunc):

# check that %23 (#) is not escaped where it shouldn't be
'http://test.example/?p=%23val#test-%23-val%25': 'http://test.example/?p=%23val#test-%23-val%25',
# check that %20 or %25 is not unescaped to ' ' or %
'http://test.example/%25/?p=%20val%20%25' : 'http://test.example/%25/?p=%20val%20%25',
# check that %25 is not unescaped to %
'http://test.example/%25/?p=val%25ue' : 'http://test.example/%25/?p=val%25ue',
"http://test.domain/I%C3%B1t%C3%ABrn%C3%A2ti%C3%B4n%EF%BF%BDliz%C3%A6ti%C3%B8n" : "http://test.domain/I\xc3\xb1t\xc3\xabrn\xc3\xa2ti\xc3\xb4n\xef\xbf\xbdliz\xc3\xa6ti\xc3\xb8n",
# check that spaces in paths are not escaped
'http://test.example/abcde%20def' : 'http://test.example/abcde def',
# check that %20 in paths, params, query strings, and fragments are unescaped
'http://test.example/abcde%20def?que%20ry=str%20ing#frag%20ment' : 'http://test.example/abcde def?que ry=str ing#frag ment',
# check that spaces are collated to '+'
"http://test.example/path/with a%20space+/" : "http://test.example/path/with a space+/", # spaces in apths are ok
"http://test.example/path;par%20ams/with a%20space+/" : "http://test.example/path;par ams/with a space+/", # spaces in paths are ok
"http://[2001:db8:1f70::999:de8:7648:6e8]/test" : "http://[2001:db8:1f70::999:de8:7648:6e8]/test", #ipv6 address
"http://[::ffff:192.168.1.1]/test" : "http://[::ffff:192.168.1.1]/test", # ipv4 address in ipv6 notation
"http://[::ffff:192.168.1.1]:80/test" : "http://[::ffff:192.168.1.1]/test", # ipv4 address in ipv6 notation
Expand Down
9 changes: 5 additions & 4 deletions urlnorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CHANGES:
1.1.4 - unescape " " in params, query string, and fragments
1.1.3 - don't escape " " in path
1.1.2 - leave %20 as %20, collate ' ' to %20, leave '+' as '+'
1.1 - collate %20 and ' ' to '+'
Expand Down Expand Up @@ -64,7 +65,7 @@
"""

# also update in setup.py
__version__ = "1.1.2"
__version__ = "1.1.4"

from urlparse import urlparse, urlunparse
from string import lower
Expand Down Expand Up @@ -103,9 +104,9 @@ class InvalidUrl(Exception):
''
])

params_unsafe_list = set(' ?=+%#;')
qs_unsafe_list = set(' ?&=+%#')
fragment_unsafe_list = set(' +%#')
params_unsafe_list = set('?=+%#;')
qs_unsafe_list = set('?&=+%#')
fragment_unsafe_list = set('+%#')
path_unsafe_list = set('/?;%+#')
_hextochr = dict(('%02x' % i, chr(i)) for i in range(256))
_hextochr.update(('%02X' % i, chr(i)) for i in range(256))
Expand Down

0 comments on commit 197a352

Please sign in to comment.