From be21d7830fc5d8adb4362db8ebbfa4c0d2dde0ae Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 2 May 2026 05:59:00 -0500 Subject: [PATCH] fix: update filename sanitization to allow hyphens as literal characters --- .../app/src/main/java/com/meshchatx/MeshchatDownloadUtils.java | 3 ++- .../src/test/java/com/meshchatx/MeshchatDownloadUtilsTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/meshchatx/MeshchatDownloadUtils.java b/android/app/src/main/java/com/meshchatx/MeshchatDownloadUtils.java index 8ad709d..a19da78 100644 --- a/android/app/src/main/java/com/meshchatx/MeshchatDownloadUtils.java +++ b/android/app/src/main/java/com/meshchatx/MeshchatDownloadUtils.java @@ -16,7 +16,8 @@ final class MeshchatDownloadUtils { if (base.isEmpty()) { return "download.bin"; } - base = base.replaceAll("[^A-Za-z0-9._ -]+", "_").trim(); + // Hyphen must be first or last in the class so it is literal, not a range (space..hyphen would include '*'). + base = base.replaceAll("[^A-Za-z0-9._ \\-]+", "_").trim(); if (base.isEmpty()) { return "download.bin"; } diff --git a/android/app/src/test/java/com/meshchatx/MeshchatDownloadUtilsTest.java b/android/app/src/test/java/com/meshchatx/MeshchatDownloadUtilsTest.java index 1761ea8..73cf40a 100644 --- a/android/app/src/test/java/com/meshchatx/MeshchatDownloadUtilsTest.java +++ b/android/app/src/test/java/com/meshchatx/MeshchatDownloadUtilsTest.java @@ -19,7 +19,7 @@ public class MeshchatDownloadUtilsTest { @Test public void sanitize_replacesUnsafeCharacters() { - Assert.assertEquals("mesh_x_folders.json", MeshchatDownloadUtils.sanitizeFileName("mesh:x?folders*.json")); + Assert.assertEquals("mesh_x_folders_.json", MeshchatDownloadUtils.sanitizeFileName("mesh:x?folders*.json")); } @Test