From aaf71bfbcc2ec1ed62777af69c882f7d4d264497 Mon Sep 17 00:00:00 2001 From: Marc Strapetz Date: Mon, 19 Feb 2018 11:26:09 +0100 Subject: [PATCH] gitignore/gitattributes: fix matching of \r Patterns should treat \r in file names as normal characters Change-Id: Ica3e0fa4a58acf5326db46bb28571fe5f20f6cd2 Signed-off-by: Marc Strapetz --- .../eclipse/jgit/attributes/AttributesMatcherTest.java | 8 ++++++++ .../tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java | 9 +++++++++ .../src/org/eclipse/jgit/ignore/internal/Strings.java | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java index 196c4f7d9c..08553e1ae4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java @@ -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. diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java index 2a1721e66c..4bd1dab3e8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java @@ -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") diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java index 9b255b41c3..41923eed18 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java @@ -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, -- 2.39.5