diff --git a/source/net/filebot/util/FileUtilities.java b/source/net/filebot/util/FileUtilities.java index 0e17b042..846cf29b 100644 --- a/source/net/filebot/util/FileUtilities.java +++ b/source/net/filebot/util/FileUtilities.java @@ -323,13 +323,13 @@ public final class FileUtilities { } 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) { - String base = getName(prime).trim().toLowerCase(); - derivate = derivate.trim().toLowerCase(); - return derivate.startsWith(base); + if (s.startsWith(n)) { + return s.length() == n.length() || !Character.isLetterOrDigit(s.charAt(n.length())); // e.g. x.z is not considered derived from xy.z + } + return false; } public static boolean isDerivedByExtension(File derivate, File prime) { diff --git a/test/net/filebot/util/FileUtilitiesTest.java b/test/net/filebot/util/FileUtilitiesTest.java index 8ebf0c14..9fc7185a 100644 --- a/test/net/filebot/util/FileUtilitiesTest.java +++ b/test/net/filebot/util/FileUtilitiesTest.java @@ -1,11 +1,11 @@ package net.filebot.util; - import static org.junit.Assert.*; -import org.junit.Test; +import java.io.File; +import org.junit.Test; public class FileUtilitiesTest { @@ -15,7 +15,6 @@ public class FileUtilitiesTest { assertFalse(FileUtilities.hasExtension(".hidden", "txt")); } - @Test public void getExtension() { assertEquals("txt", FileUtilities.getExtension("abc.txt")); @@ -28,7 +27,6 @@ public class FileUtilitiesTest { assertEquals(null, FileUtilities.getExtension("archive.invalid extension")); } - @Test public void getNameWithoutExtension() { assertEquals("abc", FileUtilities.getNameWithoutExtension("abc.txt")); @@ -41,4 +39,13 @@ public class FileUtilitiesTest { 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"))); + } + }