diff --git a/tests/test_import_flow.py b/tests/test_import_flow.py index 4aca60c..b378155 100644 --- a/tests/test_import_flow.py +++ b/tests/test_import_flow.py @@ -160,7 +160,7 @@ def test_audio_tags_written_on_import(client): }]}) assert resp.json()["results"][0]["ok"] - dest = root / "Ulf Blanck" / "Die drei ??? Kids Folge 085" # "?" becomes fullwidth + dest = root / "Ulf Blanck" / "Die drei ??? Kids Folge 085" files = sorted(dest.iterdir()) tags = ID3(files[0]) assert str(tags["TALB"]) == "Die drei ??? Kids Folge 085" diff --git a/tests/test_naming.py b/tests/test_naming.py index b621d00..00f9266 100644 --- a/tests/test_naming.py +++ b/tests/test_naming.py @@ -9,9 +9,9 @@ def req(**kw): return SimpleNamespace(**base) -def test_sanitize_replaces_forbidden_chars(): - assert sanitize("Die drei ???") == "Die drei ???" - assert sanitize("a/b") == "a⧸b" +def test_sanitize_keeps_special_chars_but_strips_separators(): + assert sanitize("Die drei ???") == "Die drei ???" + assert sanitize("a/b\\c") == "abc" assert "\x01" not in sanitize("a\x01b") diff --git a/wordarr/naming.py b/wordarr/naming.py index d0b03a3..805f6d1 100644 --- a/wordarr/naming.py +++ b/wordarr/naming.py @@ -1,16 +1,12 @@ import re -# characters not allowed in (Windows/SMB-safe) file names are replaced with -# fullwidth lookalikes so names like "Die drei ???" stay readable -_REPLACEMENTS = str.maketrans({ - "<": "<", ">": ">", ":": ":", '"': """, "/": "⧸", - "\\": "⧹", "|": "|", "?": "?", "*": "*", -}) -_CONTROL = re.compile(r"[\x00-\x1f]") +# only path separators and control chars are truly forbidden on Linux; keep +# everything else literal so names like "Die drei ???" survive as-is +_FORBIDDEN = re.compile(r"[/\\\x00-\x1f]") def sanitize(part: str, max_len: int = 120) -> str: - part = _CONTROL.sub("", part.translate(_REPLACEMENTS)).strip(" .") + part = _FORBIDDEN.sub("", part).strip(" .") part = re.sub(r"\s+", " ", part) return part[:max_len].strip(" .") or "Unknown"