mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
tests: Fix text sanitization tests on Windows
Fix a failing test case on Windows, due to a character that cannot exist in a filename.
This commit is contained in:
parent
ff1677672e
commit
63b12abbdf
1 changed files with 12 additions and 4 deletions
|
@ -123,15 +123,23 @@ def uncommon_text() -> str:
|
||||||
def uncommon_filename(uncommon_text: str) -> str:
|
def uncommon_filename(uncommon_text: str) -> str:
|
||||||
"""Craft a filename with Unicode characters that are considered not common.
|
"""Craft a filename with Unicode characters that are considered not common.
|
||||||
|
|
||||||
We reuse the same uncommon string as above, with a small exception for macOS.
|
We reuse the same uncommon string as above, with a small exception for macOS and
|
||||||
Because the APFS filesystem in macOS accepts only UTF-8 encoded strings [1], we
|
Windows.
|
||||||
cannot create a filename with invalid Unicode characters. So, in order to test the
|
|
||||||
rest of the corner cases, we replace U+DCF0 with an empty string.
|
Because the NTFS filesystem in Windows and APFS filesystem in macOS accept only
|
||||||
|
UTF-8 encoded strings [1], we cannot create a filename with invalid Unicode
|
||||||
|
characters. So, in order to test the rest of the corner cases, we replace U+DCF0
|
||||||
|
with an empty string.
|
||||||
|
|
||||||
|
Windows has the extra restriction that it cannot have escape characters in
|
||||||
|
filenames, so we replace the ASCII Escape character (\033 / U+001B) as well.
|
||||||
|
|
||||||
[1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
|
[1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
|
||||||
"""
|
"""
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
uncommon_text = uncommon_text.replace("\udcf0", "")
|
uncommon_text = uncommon_text.replace("\udcf0", "")
|
||||||
|
elif platform.system() == "Windows":
|
||||||
|
uncommon_text = uncommon_text.replace("\udcf0", "").replace("\033", "")
|
||||||
return uncommon_text + ".pdf"
|
return uncommon_text + ".pdf"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue