Skip to content

Instantly share code, notes, and snippets.

@geusebi
Last active February 22, 2016 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geusebi/b152f1ee17a66a9bbeee to your computer and use it in GitHub Desktop.
Save geusebi/b152f1ee17a66a9bbeee to your computer and use it in GitHub Desktop.
Alternative safe_join
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