summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Pavlenko <pavlenko@tmatesoft.com>2017-12-15 21:15:35 +0100
committerDavid Pursehouse <david.pursehouse@gmail.com>2017-12-21 18:33:22 -0500
commit279eaf069004b8dca523f1ecb231c1df02ac9031 (patch)
treeb89b16a00cfc57b6b5439b557d20852c3191ac58
parent085d1f9599f6dae8fe90e2dd7df195d1c9736ec4 (diff)
downloadjgit-279eaf069004b8dca523f1ecb231c1df02ac9031.tar.gz
jgit-279eaf069004b8dca523f1ecb231c1df02ac9031.zip
Strings#convertGlob: fix escaping of patterns like [\[].
Originally the patterns were escaped twice leading to wrong matching results. Bug: 528886 Change-Id: I26e201b4b0ef51cac08f940b76f381260fa925ca Signed-off-by: Dmitry Pavlenko <pavlenko@tmatesoft.com> Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java33
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java27
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java5
4 files changed, 72 insertions, 1 deletions
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 23c416a45b..72cc1d1814 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
@@ -382,6 +382,39 @@ public class AttributesMatcherTest {
assertEquals(r.getAttributes().get(2).toString(), "attribute3=value");
}
+ @Test
+ public void testBracketsInGroup() {
+ //combinations of brackets in brackets, escaped and not
+
+ String[] patterns = new String[]{"[[\\]]", "[\\[\\]]"};
+ for (String pattern : patterns) {
+ assertNotMatched(pattern, "");
+ assertNotMatched(pattern, "[]");
+ assertNotMatched(pattern, "][");
+ assertNotMatched(pattern, "[\\[]");
+ assertNotMatched(pattern, "[[]");
+ assertNotMatched(pattern, "[[]]");
+ assertNotMatched(pattern, "[\\[\\]]");
+
+ assertMatched(pattern, "[");
+ assertMatched(pattern, "]");
+ }
+
+ patterns = new String[]{"[[]]", "[\\[]]"};
+ for (String pattern : patterns) {
+ assertNotMatched(pattern, "");
+ assertMatched(pattern, "[]");
+ assertNotMatched(pattern, "][");
+ assertNotMatched(pattern, "[\\[]");
+ assertNotMatched(pattern, "[[]");
+ assertNotMatched(pattern, "[[]]");
+ assertNotMatched(pattern, "[\\[\\]]");
+
+ assertNotMatched(pattern, "[");
+ assertNotMatched(pattern, "]");
+ }
+ }
+
/**
* 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/attributes/CGitAttributesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
index 7a74fd3cb6..34838138e3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
@@ -378,4 +378,12 @@ public class CGitAttributesTest extends RepositoryTestCase {
writeTrashFile(".gitattributes", "new/ bar\n");
assertSameAsCGit();
}
+
+ @Test
+ public void testBracketsInGroup() throws Exception {
+ createFiles("[", "]", "[]", "][", "[[]", "[]]", "[[]]");
+ writeTrashFile(".gitattributes", "[[]] bar1\n" + "[\\[]] bar2\n"
+ + "[[\\]] bar3\n" + "[\\[\\]] bar4\n");
+ assertSameAsCGit();
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
index baf9f9c95f..ee8191ffc5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
@@ -241,4 +241,31 @@ public class CGitIgnoreTest extends RepositoryTestCase {
assertSameAsCGit();
}
+ @Test
+ public void testUnescapedBracketsInGroup() throws Exception {
+ createFiles("[", "]", "[]", "][", "[[]", "[]]", "[[]]");
+ writeTrashFile(".gitignore", "[[]]\n");
+ assertSameAsCGit();
+ }
+
+ @Test
+ public void testEscapedFirstBracketInGroup() throws Exception {
+ createFiles("[", "]", "[]", "][", "[[]", "[]]", "[[]]");
+ writeTrashFile(".gitignore", "[\\[]]\n");
+ assertSameAsCGit();
+ }
+
+ @Test
+ public void testEscapedSecondBracketInGroup() throws Exception {
+ createFiles("[", "]", "[]", "][", "[[]", "[]]", "[[]]");
+ writeTrashFile(".gitignore", "[[\\]]\n");
+ assertSameAsCGit();
+ }
+
+ @Test
+ public void testEscapedBothBracketsInGroup() throws Exception {
+ createFiles("[", "]", "[]", "][", "[[]", "[]]", "[[]]");
+ writeTrashFile(".gitignore", "[\\[\\]]\n");
+ assertSameAsCGit();
+ }
}
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 79df1511d1..800cdb9952 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
@@ -363,7 +363,10 @@ public class Strings {
case '[':
if (in_brackets > 0) {
- sb.append('\\').append('[');
+ if (!seenEscape) {
+ sb.append('\\');
+ }
+ sb.append('[');
ignoreLastBracket = true;
} else {
if (!seenEscape) {