x.z is not considered derived from xy.z

@see https://www.filebot.net/forums/viewtopic.php?p=24206#p24206
This commit is contained in:
Reinhard Pointner 2016-11-06 03:59:03 +08:00
parent 4f1bd2c7f9
commit be9fc83fcd
2 changed files with 17 additions and 10 deletions

View File

@ -323,13 +323,13 @@ public final class FileUtilities {
} }
public static boolean isDerived(File derivate, File prime) { public static boolean isDerived(File derivate, File prime) {
return isDerived(getName(derivate), prime); String n = getName(prime).toLowerCase();
} String s = getName(derivate).toLowerCase();
public static boolean isDerived(String derivate, File prime) { if (s.startsWith(n)) {
String base = getName(prime).trim().toLowerCase(); return s.length() == n.length() || !Character.isLetterOrDigit(s.charAt(n.length())); // e.g. x.z is not considered derived from xy.z
derivate = derivate.trim().toLowerCase(); }
return derivate.startsWith(base); return false;
} }
public static boolean isDerivedByExtension(File derivate, File prime) { public static boolean isDerivedByExtension(File derivate, File prime) {

View File

@ -1,11 +1,11 @@
package net.filebot.util; package net.filebot.util;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Test; import java.io.File;
import org.junit.Test;
public class FileUtilitiesTest { public class FileUtilitiesTest {
@ -15,7 +15,6 @@ public class FileUtilitiesTest {
assertFalse(FileUtilities.hasExtension(".hidden", "txt")); assertFalse(FileUtilities.hasExtension(".hidden", "txt"));
} }
@Test @Test
public void getExtension() { public void getExtension() {
assertEquals("txt", FileUtilities.getExtension("abc.txt")); assertEquals("txt", FileUtilities.getExtension("abc.txt"));
@ -28,7 +27,6 @@ public class FileUtilitiesTest {
assertEquals(null, FileUtilities.getExtension("archive.invalid extension")); assertEquals(null, FileUtilities.getExtension("archive.invalid extension"));
} }
@Test @Test
public void getNameWithoutExtension() { public void getNameWithoutExtension() {
assertEquals("abc", FileUtilities.getNameWithoutExtension("abc.txt")); assertEquals("abc", FileUtilities.getNameWithoutExtension("abc.txt"));
@ -41,4 +39,13 @@ public class FileUtilitiesTest {
assertEquals("archive.invalid extension", FileUtilities.getNameWithoutExtension("archive.invalid extension")); assertEquals("archive.invalid extension", FileUtilities.getNameWithoutExtension("archive.invalid extension"));
} }
@Test
public void isDerived() {
assertTrue(FileUtilities.isDerived(new File("avatar.eng.srt"), new File("avatar.mp4")));
assertTrue(FileUtilities.isDerived(new File("1.z"), new File("1.xyz")));
assertTrue(FileUtilities.isDerived(new File("1.xyz"), new File("1.z")));
assertFalse(FileUtilities.isDerived(new File("1.eng.srt"), new File("10.mp4")));
assertFalse(FileUtilities.isDerived(new File("10.z"), new File("1.mp4")));
}
} }