1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Fix filename generation and add testcasce

Fixes #1169
This commit is contained in:
cpfeiffer 2018-08-01 19:33:02 +02:00
parent 7f1c0521ea
commit df84927954
2 changed files with 20 additions and 1 deletions

View File

@ -318,6 +318,6 @@ public class FileUtils {
* @return the valid file name
*/
public static String makeValidFileName(String name) {
return name.replaceAll("\0/:\\r\\n\\\\", "_");
return name.replaceAll("[\0/:\\r\\n\\\\]", "_");
}
}

View File

@ -0,0 +1,19 @@
package nodomain.freeyourgadget.gadgetbridge.test;
import org.junit.Test;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import static org.junit.Assert.assertEquals;
public class FileUtilsTest extends TestBase {
@Test
public void testValidFileName() {
String tempName = "foo:bar";
assertEquals("foo_bar", FileUtils.makeValidFileName(tempName));
tempName = "fo\no::bar";
assertEquals("fo_o__bar", FileUtils.makeValidFileName(tempName));
}
}