fix: update filename sanitization to allow hyphens as literal characters

This commit is contained in:
Ivan
2026-05-02 05:59:00 -05:00
parent 42995227f1
commit be21d7830f
2 changed files with 3 additions and 2 deletions
@@ -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";
}
@@ -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