1 Commits

Author SHA1 Message Date
Frank Schwenk 0f19a562ce fix: sanitize_stem handles path-like stems with leading dots
CI / lint-and-test (push) Successful in 47s
Path(".._evil").stem returns "." and fell back to the default "photo".
Strip leading/trailing dots before Path.stem so "../evil" becomes "evil".
2026-09-25 08:42:15 +02:00
+3 -2
View File
@@ -307,10 +307,11 @@ _UNSAFE_STEM_RE = re.compile(r"[^\w.\-]+", re.UNICODE)
def sanitize_stem(name: str) -> str:
"""Safe basename stem for flat files (no path separators / junk)."""
# Replace separators before Path.stem so "a/b" → "a_b", not "b".
# Replace separators before Path.stem so "a/b" -> "a_b", not "b".
stem = (name or "").replace("/", "_").replace("\\", "_")
stem = Path(stem).stem
# Strip leading/trailing dots first; Path(".._evil").stem returns ".".
stem = stem.strip().strip(".")
stem = Path(stem).stem
stem = _UNSAFE_STEM_RE.sub("_", stem).strip("._")
return stem or "photo"