From: Guido van Rossum Date: Fri, 11 Apr 1997 19:09:51 +0000 (+0000) Subject: (Jack+Guido:) interpret ../ in basejoin() according to RFC1808. X-Git-Tag: v1.5a1~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54a1d0bc699ea0cbe4fbe79dfe3ddcd427ab807e;p=python (Jack+Guido:) interpret ../ in basejoin() according to RFC1808. --- diff --git a/Lib/urllib.py b/Lib/urllib.py index e57311b519..a8a579bb90 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -592,6 +592,13 @@ def basejoin(base, url): else: # remove last file component basepath = basepath[:i+1] + # Interpret ../ (important because of symlinks) + while basepath and path[:3] == '../': + path = path[3:] + i = string.rfind(basepath, '/') + if i > 0: + basepath = basepath[:i-1] + path = basepath + path if type and host: return type + '://' + host + path elif type: return type + ':' + path