diff --git a/test_urlnorm.py b/test_urlnorm.py index e1f7916..f9ae2dd 100644 --- a/test_urlnorm.py +++ b/test_urlnorm.py @@ -52,6 +52,10 @@ def pytest_generate_tests(metafunc): # python 2.5 urlparse doesn't handle unknown protocols, so skipping this for now #"itms://itunes.apple.com/us/app/touch-pets-cats/id379475816?mt=8#23161525,,1293732683083,260430,tw" : "itms://itunes.apple.com/us/app/touch-pets-cats/id379475816?mt=8#23161525,,1293732683083,260430,tw", #can handle itms:// + #'http://example.com/../foo' should normalize to 'http://example.com/foo' + "http://example.com/../foo": "http://example.com/foo", + "http://example.com//foo/../../bar": "http://example.com/bar", + "http://example.com/../foo/../bar/../baz": "http://example.com/baz", } for bad, good in tests.items(): metafunc.addcall(funcargs=dict(bad=bad, good=good)) @@ -83,15 +87,15 @@ def pytest_generate_tests(metafunc): '/foo/bar/../..': '/', '/foo/bar/../../': '/', '/foo/bar/../../baz': '/baz', - '/foo/bar/../../../baz': '/../baz', + '/foo/bar/../../../baz': '/baz', '/foo/bar/../../../../baz': '/baz', '/./foo': '/foo', - '/../foo': '/../foo', + '/../foo': '/foo', '/foo.': '/foo.', '/.foo': '/.foo', '/foo..': '/foo..', '/..foo': '/..foo', - '/./../foo': '/../foo', + '/./../foo': '/foo', '/./foo/.': '/foo/', '/foo/./bar': '/foo/bar', '/foo/../bar': '/bar', diff --git a/urlnorm.py b/urlnorm.py index 481a1d6..e515031 100644 --- a/urlnorm.py +++ b/urlnorm.py @@ -173,6 +173,8 @@ def norm_path(scheme, path): while 1: path = _collapse.sub('/', path, 1) if last_path == path: + # 'http://example.com/../foo' should normalize to 'http://example.com/foo' + path = re.sub('^/\.\./', '/', path) break last_path = path path = unquote_path(path)