]> source.dussan.org Git - jgit.git/commitdiff
gitignore/gitattributes: fix matching of \r 40/117640/5
authorMarc Strapetz <marc.strapetz@syntevo.com>
Mon, 19 Feb 2018 10:26:09 +0000 (11:26 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 27 Oct 2018 08:24:05 +0000 (04:24 -0400)
Patterns should treat \r in file names as normal characters

Change-Id: Ica3e0fa4a58acf5326db46bb28571fe5f20f6cd2
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java
org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java

index 196c4f7d9cb8e9d773714b0b2e96ca288abaa6e6..08553e1ae4eaa0caddaa8fc58b61f068021b4a18 100644 (file)
@@ -415,6 +415,14 @@ public class AttributesMatcherTest {
                }
        }
 
+       @Test
+       public void testFileNameWithLineTerminator() {
+               assertMatched("a?", "a\r");
+               assertMatched("a?", "dir/a\r");
+               assertMatched("*a", "\ra");
+               assertMatched("dir/*a*", "dir/\ra\r");
+       }
+
        /**
         * Check for a match. If target ends with "/", match will assume that the
         * target is meant to be a directory.
index 2a1721e66caa5fb1020095d5d247eca5b18668aa..4bd1dab3e8ec66ea1026641c668e36f8146f1bdd 100644 (file)
@@ -512,6 +512,15 @@ public class FastIgnoreRuleTest {
                assertMatched("x/**/", "x/y/a/");
        }
 
+       @Test
+       public void testFileNameWithLineTerminator() {
+               assertMatched("a?", "a\r");
+               assertMatched("a?", "dir/a\r");
+               assertMatched("a?", "a\r/file");
+               assertMatched("*a", "\ra");
+               assertMatched("dir/*a*", "dir/\ra\r");
+       }
+
        private void assertMatched(String pattern, String path) {
                boolean match = match(pattern, path);
                String result = path + " is " + (match ? "ignored" : "not ignored")
index 9b255b41c36366c39c73a3aa44779f65c237f6e6..41923eed183fbea03cdc199b6dd35cca0f9c266d 100644 (file)
@@ -443,7 +443,7 @@ public class Strings {
                if (in_brackets > 0)
                        throw new InvalidPatternException("Not closed bracket?", pattern); //$NON-NLS-1$
                try {
-                       return Pattern.compile(sb.toString());
+                       return Pattern.compile(sb.toString(), Pattern.DOTALL);
                } catch (PatternSyntaxException e) {
                        throw new InvalidPatternException(
                                        MessageFormat.format(JGitText.get().invalidIgnoreRule,