Browse Source

gitignore/gitattributes: fix matching of \r

Patterns should treat \r in file names as normal characters

Change-Id: Ica3e0fa4a58acf5326db46bb28571fe5f20f6cd2
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
stable-5.2
Marc Strapetz 7 years ago committed by Matthias Sohn
parent
commit
aaf71bfbcc
  1. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java
  2. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java
  3. 2
      org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java

8
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.

9
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")

2
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,

Loading…
Cancel
Save