diff --git a/WHATSNEW b/WHATSNEW index dce6cb819..fd5202377 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -134,10 +134,11 @@ Changes that could break older environments: versions of Ant. Bugzilla Report 36748. - * globmapper didn't work properly if the "to" pattern didn't contain - a "*". In particular it implicitly added a * to the end of the - pattern. This is no longer the case. If you relied on this - behavior you will now need to explicitly specify the trailing *. + * globmapper didn't work properly if the "to" or "from" patterns + didn't contain a "*". In particular it implicitly added a * to the + end of the pattern(s). This is no longer the case. If you relied + on this behavior you will now need to explicitly specify the + trailing "*". Bugzilla Report 46506. * silently ignored missing resources even with diff --git a/src/etc/testcases/taskdefs/pathconvert.xml b/src/etc/testcases/taskdefs/pathconvert.xml index a9b109ef6..1cdcc8cda 100644 --- a/src/etc/testcases/taskdefs/pathconvert.xml +++ b/src/etc/testcases/taskdefs/pathconvert.xml @@ -31,7 +31,7 @@ - + diff --git a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java index d302d70f4..7181828e5 100644 --- a/src/main/org/apache/tools/ant/util/GlobPatternMapper.java +++ b/src/main/org/apache/tools/ant/util/GlobPatternMapper.java @@ -68,6 +68,7 @@ public class GlobPatternMapper implements FileNameMapper { // CheckStyle:VisibilityModifier ON + private boolean fromContainsStar = false; private boolean toContainsStar = false; private boolean handleDirSep = false; private boolean caseSensitive = true; @@ -106,6 +107,7 @@ public class GlobPatternMapper implements FileNameMapper { } else { fromPrefix = from.substring(0, index); fromPostfix = from.substring(index + 1); + fromContainsStar = true; } prefixLength = fromPrefix.length(); postfixLength = fromPostfix.length(); @@ -142,10 +144,16 @@ public class GlobPatternMapper implements FileNameMapper { * @return a list of converted filenames */ public String[] mapFileName(String sourceFileName) { + String modName = modifyName(sourceFileName); if (fromPrefix == null - || !modifyName(sourceFileName).startsWith(modifyName(fromPrefix)) - || !modifyName(sourceFileName).endsWith(modifyName(fromPostfix)) || (sourceFileName.length() < (prefixLength + postfixLength)) + || (!fromContainsStar + && !modName.equals(modifyName(fromPrefix)) + ) + || (fromContainsStar + && (!modName.startsWith(modifyName(fromPrefix)) + || !modName.endsWith(modifyName(fromPostfix))) + ) ) { return null; } diff --git a/src/tests/antunit/types/glob-test.xml b/src/tests/antunit/types/glob-test.xml index 9222dbb17..c4626f5dd 100644 --- a/src/tests/antunit/types/glob-test.xml +++ b/src/tests/antunit/types/glob-test.xml @@ -68,4 +68,13 @@ + + + + + + + + +