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>
tags/v5.2.0.201811281532-m3
Marc Strapetz 6 years ago
parent
commit
aaf71bfbcc

+ 8
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java View 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.

+ 9
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java View 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")

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java View 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,

Loading…
Cancel
Save