fix: sanitize_stem handles path-like stems with leading dots
CI / lint-and-test (push) Successful in 47s
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".
This commit is contained in:
+3
-2
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user