Merge pull request #4274 from ByteHamster/filename-accents
Stripping accents before generating file name
This commit is contained in:
commit
54db709fd6
|
@ -21,32 +21,28 @@ import static org.junit.Assert.assertTrue;
|
|||
@SmallTest
|
||||
public class FilenameGeneratorTest {
|
||||
|
||||
private static final String VALID1 = "abc abc";
|
||||
private static final String INVALID1 = "ab/c: <abc";
|
||||
private static final String INVALID2 = "abc abc ";
|
||||
|
||||
public FilenameGeneratorTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateFileName() throws IOException {
|
||||
String result = FileNameGenerator.generateFileName(VALID1);
|
||||
assertEquals(result, VALID1);
|
||||
String result = FileNameGenerator.generateFileName("abc abc");
|
||||
assertEquals(result, "abc abc");
|
||||
createFiles(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateFileName1() throws IOException {
|
||||
String result = FileNameGenerator.generateFileName(INVALID1);
|
||||
assertEquals(result, VALID1);
|
||||
String result = FileNameGenerator.generateFileName("ab/c: <abc");
|
||||
assertEquals(result, "abc abc");
|
||||
createFiles(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateFileName2() throws IOException {
|
||||
String result = FileNameGenerator.generateFileName(INVALID2);
|
||||
assertEquals(result, VALID1);
|
||||
String result = FileNameGenerator.generateFileName("abc abc ");
|
||||
assertEquals(result, "abc abc");
|
||||
createFiles(result);
|
||||
}
|
||||
|
||||
|
@ -62,6 +58,12 @@ public class FilenameGeneratorTest {
|
|||
assertEquals("Left - Right", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFeedTitleContainsAccents() {
|
||||
String result = FileNameGenerator.generateFileName("Äàáâãå");
|
||||
assertEquals("Aaaaaa", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidInput() {
|
||||
String result = FileNameGenerator.generateFileName("???");
|
||||
|
@ -97,14 +99,6 @@ public class FilenameGeneratorTest {
|
|||
assertTrue(testFile.exists());
|
||||
testFile.delete();
|
||||
assertTrue(testFile.createNewFile());
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
File f = new File(context.getExternalCacheDir(), VALID1);
|
||||
f.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.text.TextUtils;
|
|||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -29,6 +30,7 @@ public class FileNameGenerator {
|
|||
* characters of the given string.
|
||||
*/
|
||||
public static String generateFileName(String string) {
|
||||
string = StringUtils.stripAccents(string);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = 0; i < string.length(); i++) {
|
||||
char c = string.charAt(i);
|
||||
|
|
Loading…
Reference in New Issue