mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
tests: Add a fixture for uncommon filenames
Add a pytest fixture that crafts a filename with Unicode characters that are not considered common for this use. By default, this fixture uses an invalid Unicode character as well, but we strip it in case of macOS (APFS) since filenames must be UTF-8 encoded. [1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
This commit is contained in:
parent
94179a1d91
commit
2fa592eb69
1 changed files with 17 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
import platform
|
||||
import sys
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
@ -117,6 +118,22 @@ def uncommon_text() -> str:
|
|||
return "\033[31;1;4m BaD TeΧt \u200d ❌ \033[0m"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def uncommon_filename(uncommon_text: str) -> str:
|
||||
"""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.
|
||||
Because the APFS filesystem in macOS accepts 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.
|
||||
|
||||
[1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations
|
||||
"""
|
||||
if platform.system() == "Darwin":
|
||||
uncommon_text = uncommon_text.replace("\udcf0", "")
|
||||
return uncommon_text + ".pdf"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sanitized_text() -> str:
|
||||
"""Return a sanitized version of the uncommon_text."""
|
||||
|
|
Loading…
Reference in a new issue