Last active
February 22, 2016 07:01
Alternative safe_join
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def safe_join(directory, *pathnames): | |
pathnames = tuple(posixpath.normpath(p) for p in pathnames) | |
for filename in pathnames: | |
for sep in _os_alt_seps: | |
if sep in filename: | |
raise NotFound() | |
if os.path.isabs(filename) or \ | |
filename == '..' or \ | |
filename.startswith('../'): | |
raise NotFound() | |
return os.path.join(directory, *pathnames) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment