Skip to content

Commit

Permalink
Merge pull request #1351 from dandi/bf-sanitize-spaces
Browse files Browse the repository at this point in the history
Sanitize spaces and ,s in organized filenames
  • Loading branch information
yarikoptic committed Nov 9, 2023
2 parents b6717fb + 8d7b1a6 commit dcf05a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dandi/organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def _sanitize_value(value, field):
Of particular importance is _ which we use, as in BIDS, to separate
_key-value entries
"""
value = re.sub(r"[_*\\/<>:|\"'?%@;]", "-", value)
value = re.sub(r"[_*\\/<>:|\"'?%@;,\s]", "-", value)
if field != "extension":
value = value.replace(".", "-")
return value
Expand Down
3 changes: 3 additions & 0 deletions dandi/tests/test_organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_sanitize_value() -> None:
assert _sanitize_value("_.ext", "extension") == "-.ext"
assert _sanitize_value("_.ext", "unrelated") == "--ext"
assert _sanitize_value("A;B", "unrelated") == "A-B"
# no spaces or tabs please
assert _sanitize_value("A B\t C", "unrelated") == "A-B--C"
assert _sanitize_value("A;B,C", "unrelated") == "A-B-C"
assert _sanitize_value("A\\/B", "unrelated") == "A--B"
assert _sanitize_value("A\"'B", "unrelated") == "A--B"

Expand Down

0 comments on commit dcf05a6

Please sign in to comment.