gruns / furl

🌐 URL parsing and manipulation made easy.
Other
2.6k stars 151 forks source link

.join() and .path.normalize() incorrectly interpret base paths ending /. or /.. #159

Open andersk opened 1 year ago

andersk commented 1 year ago

When joining URLs, furl correctly treats a path /a/b/c/d/../ as equivalent to /a/b/c/, but it incorrectly treats /a/b/c/d/.. as equivalent to /a/b/c rather than /a/b/c/ (with a trailing slash). This causes further path components to be joined at the wrong level.

>>> furl("http://host/a/b/c/d/../").join("D")  # correct
furl('http://host/a/b/c/D')
>>> furl("http://host/a/b/c/d/..").join("D")  # expected furl('http://host/a/b/c/D')
furl('http://host/a/b/c/d/D')

A similar problem can be observed with .path.normalize(). This one also affects paths ending in /.:

>>> furl("http://host/a/b/c/d/./").path.normalize()  # correct
Path('/a/b/c/d/')
>>> furl("http://host/a/b/c/d/../").path.normalize()  # correct
Path('/a/b/c/')
>>> furl("http://host/a/b/c/d/.").path.normalize()  # expected Path('/a/b/c/d/')
Path('/a/b/c/d')
>>> furl("http://host/a/b/c/d/..").path.normalize()  # expected Path('/a/b/c/')
Path('/a/b/c')