mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-23 16:18:50 -05:00
Add unit tests for FileHelper.sanitizeFilename()
This commit is contained in:
parent
56c30095e2
commit
552e552e88
@ -12,6 +12,7 @@ import com.fsck.k9.K9;
|
||||
|
||||
|
||||
public class FileHelper {
|
||||
|
||||
/**
|
||||
* Regular expression that represents characters we won't allow in file names.
|
||||
*
|
||||
@ -27,7 +28,7 @@ public class FileHelper {
|
||||
*
|
||||
* @see #sanitizeFilename(String)
|
||||
*/
|
||||
private static final String INVALID_CHARACTERS = "[^\\w !#$%&'()\\-@\\^`{}~.,]+";
|
||||
private static final String INVALID_CHARACTERS = "[^\\w !#$%&'()\\-@\\^`{}~.,]";
|
||||
|
||||
/**
|
||||
* Invalid characters in a file name are replaced by this character.
|
||||
|
32
tests/src/com/fsck/k9/helper/FileHelperTest.java
Normal file
32
tests/src/com/fsck/k9/helper/FileHelperTest.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.fsck.k9.helper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
public class FileHelperTest extends TestCase {
|
||||
|
||||
public void testSanitize1() {
|
||||
checkSanitization(".._bla_", "../bla_");
|
||||
}
|
||||
|
||||
public void testSanitize2() {
|
||||
checkSanitization("_etc_bla", "/etc/bla");
|
||||
}
|
||||
|
||||
public void testSanitize3() {
|
||||
checkSanitization("_пPп", "+пPп");
|
||||
}
|
||||
|
||||
public void testSanitize4() {
|
||||
checkSanitization(".東京_!", ".東京?!");
|
||||
}
|
||||
|
||||
public void testSanitize5() {
|
||||
checkSanitization("Plan 9", "Plan 9");
|
||||
}
|
||||
|
||||
private void checkSanitization(String expected, String actual) {
|
||||
assertEquals(expected, FileHelper.sanitizeFilename(actual));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user