Stvad / CrowdAnki

Plugin for Anki SRS designed to facilitate cooperation on creation of notes and decks.
MIT License
520 stars 44 forks source link

Sanitize ascii control characters (they're not allowed on Windows) #148

Closed aplaice closed 2 years ago

aplaice commented 2 years ago

Fix #147.

Unlike Linux, Windows doesn't allow ASCII control characters (codepoint < 32) in filenames. See:

https://stackoverflow.com/a/31976060/6598435

https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions

For consistency, we should remove them always.

This might be a moot issue, since in recent versions of Anki (2.1.43 tested) it seems that all such control characters (including \n) are already filtered out from deck names, but I don't think it hurts.

\n will be double-counted, but I think it's best to keep it explicitly for readability (and since we're using a set, duplication doesn't matter).

The join takes just 5 μs, so I think replacing it with the "computed" string is not worth the drop in readability.