2 ms·
So I was curious what translate_path does: def translate_path(self, path): """Translate a /-separated PATH to the local filename syntax. C
by jwilk 10y ago
So I was curious what translate_path does:
def translate_path(self, path):
"""Translate a /-separated PATH to the local filename syntax.
Components that mean special things to the local file system
(e.g. drive or directory names) are ignored. (XXX They should
probably be diagnosed.)
"""
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = posixpath.normpath(urllib.unquote(path))
words = path.split('/')
words = filter(None, words)
path = os.getcwd()
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word)
return path
That... that doesn't make any sense.
- jwilk 10y agoOh, and thanks to urllib.unquote, I can disguise slashes as "%2f", so the tightened regexp doesn't help.
- jwilk 10y agoNever mind me, I misread how this function is used. Apparently this code was copied from stdlib, including a different directory traversal bug on Windows: https://bugs.python.org/issue26657 https://bugs.python.org/issue26657