Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
253850e2 by cal0pteryx at 2026-04-07T23:39:32+02:00
cq: Add test for sanitizing RTL codepoints in file names
- - - - -
a26f12ec by cal0pteryx at 2026-04-07T23:40:57+02:00
imprv: File transfers: Sanitize RTL codepoints from displyed file names
- - - - -
3 changed files:
- gajim/common/helpers.py
- gajim/common/util/preview.py
- test/common/test_sanitize_filename.py
Changes:
=====================================
gajim/common/helpers.py
=====================================
@@ -84,7 +84,7 @@ def sanitize_filename(filename: str) -> str:
'''
# Remove right-to-left override U+202E (commonly used to spoof extensions)
- filename = "".join(char for char in filename if ord(char) != 8238)
+ filename = filename.replace("\u202E", "")
if sys.platform == 'win32':
blacklist = ['\\', '/', ':', '*', '?', '?', '"', '<', '>', '|', '\0']
=====================================
gajim/common/util/preview.py
=====================================
@@ -82,7 +82,8 @@ def fmt(f: float) -> str:
def filename_from_uri(uri: str) -> str:
urlparts = urlparse(unquote(uri))
path = Path(urlparts.path)
- return path.name
+ # Remove right-to-left override U+202E (commonly used to spoof extensions)
+ return path.name.replace("\u202e", "")
def contains_audio_streams(file_path: Path) -> bool:
=====================================
test/common/test_sanitize_filename.py
=====================================
@@ -63,6 +63,10 @@ def test_extensions(self):
sanitize_filename("X" * 100 + "." + "X" * 400 +
".pdf").endswith(".pdf")
)
+ def test_right_to_left_codepoint(self):
+ file_name = "test__fdp.exe" # noqa: PLE2502
+ self.assertEqual(sanitize_filename(file_name), "test__fdp.exe")
+
if __name__ == "__main__":
unittest.main()
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/dfbfa80653f1f570e68dda0701be0fc7a5a5782a...a26f12ecc798db1514bdb998a49efd35a403912d
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/dfbfa80653f1f570e68dda0701be0fc7a5a5782a...a26f12ecc798db1514bdb998a49efd35a403912d
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]