Normalize relative media paths.

This commit is contained in:
2026-05-16 22:25:52 +00:00
parent c3f5ac2f6e
commit 76c4cc0829
+8 -8
View File
@@ -142,19 +142,19 @@ def make_relative_path(
path: Optional[str], root: Optional[str] = None
) -> Optional[str]:
"""
Convert an absolute path to a path relative to the given root.
Convert an absolute path to a posix-style path relative to the given root.
If root is None, returns the path unchanged.
If root is None, returns the path as a posix string unchanged.
"""
if path is None:
return None
p = Path(path)
if root is None:
return path
root_str = str(root).rstrip("/")
if path.startswith(root_str):
rel = path[len(root_str) :]
return rel.lstrip("/")
return path
return p.as_posix()
try:
return p.relative_to(root).as_posix()
except ValueError:
return p.as_posix()
def sanitize_filename(name: str) -> str: