make sure we do not get backslashes into item paths

on windows, we also want slashes, not backslashes.
This commit is contained in:
Thomas Waldmann 2023-06-10 12:52:00 +02:00
parent db96c0c487
commit b7ce3b1156
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 2 additions and 0 deletions

View File

@ -229,6 +229,8 @@ def make_path_safe(path):
`path` contain any '..' elements. `path` contain any '..' elements.
""" """
path = path.lstrip("/") path = path.lstrip("/")
if "\\" in path: # borg always wants slashes, never backslashes.
raise ValueError(f"unexpected backslash(es) in path {path!r}")
if path.startswith("../") or "/../" in path or path.endswith("/..") or path == "..": if path.startswith("../") or "/../" in path or path.endswith("/..") or path == "..":
raise ValueError(f"unexpected '..' element in path {path!r}") raise ValueError(f"unexpected '..' element in path {path!r}")
path = os.path.normpath(path) path = os.path.normpath(path)