1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Add unit tests for FileHelper.sanitizeFilename()

This commit is contained in:
Art O Cathain 2014-11-11 18:07:00 +00:00 committed by cketti
parent 56c30095e2
commit 552e552e88
2 changed files with 34 additions and 1 deletions

View File

@ -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.

View 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));
}
}