Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-09-26 16:21:14 +0000
committerAndrey Loskutov2015-09-30 16:20:05 +0000
commit1a2b4e246dc33f98b40ef5d9a202c4efd862044f (patch)
tree066deec8ec0c85746671185cf908aae44fca5305
parent4255e6f430c63b1e4d3e815946c6439c42ae1f41 (diff)
downloadjgit-1a2b4e246dc33f98b40ef5d9a202c4efd862044f.tar.gz
jgit-1a2b4e246dc33f98b40ef5d9a202c4efd862044f.tar.xz
jgit-1a2b4e246dc33f98b40ef5d9a202c4efd862044f.zip
[ignore rules] fix for handling unmatched '[' brackets
This patch makes JGit parsing of ignore rules containing unmatched '[' bracket compatible to the Git CLI. Since '[' starts character group, Git tries to parse the ignore rule as a shell glob pattern and if the character group is not closed, the glob pattern is invalid and so the ignore rule never matches anything. See also http://article.gmane.org/gmane.comp.version-control.git/278699. Bug: 478490 Change-Id: I734a4d14fcdd721070e3f75d57e33c2c0700d503 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreRuleSpecialCasesTest.java55
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java4
3 files changed, 56 insertions, 4 deletions
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 2c04787e3d..480e326507 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
@@ -54,6 +54,7 @@ public class FastIgnoreRuleTest {
@Test
public void testSimpleCharClass() {
+ assertMatched("][a]", "]a");
assertMatched("[a]", "a");
assertMatched("][a]", "]a");
assertMatched("[a]", "a/");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreRuleSpecialCasesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreRuleSpecialCasesTest.java
index f8eb126826..567f3d866c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreRuleSpecialCasesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreRuleSpecialCasesTest.java
@@ -768,7 +768,7 @@ public class IgnoreRuleSpecialCasesTest {
@Test
public void testSpecialGroupCase9() throws Exception {
- assertMatch("][", "][", true);
+ assertMatch("][", "][", false);
}
@Test
@@ -968,6 +968,59 @@ public class IgnoreRuleSpecialCasesTest {
assertMatch("[a{}()b][a{}()b]?[a{}()b][a{}()b]", "{}x()", true);
assertMatch("x*{x}3", "xa{x}3", true);
assertMatch("a*{x}3", "axxx", false);
+
+ assertMatch("?", "[", true);
+ assertMatch("*", "[", true);
+
+ // Escaped bracket matches, but see weird things below...
+ assertMatch("\\[", "[", true);
+ }
+
+ /**
+ * The ignore rules here <b>do not match</b> any paths because single '['
+ * begins character group and the entire rule cannot be parsed due the
+ * invalid glob pattern. See
+ * http://article.gmane.org/gmane.comp.version-control.git/278699.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBracketsUnmatched1() throws Exception {
+ assertMatch("[", "[", false);
+ assertMatch("[*", "[", false);
+ assertMatch("*[", "[", false);
+ assertMatch("*[", "a[", false);
+ assertMatch("[a][", "a[", false);
+ assertMatch("*[", "a", false);
+ assertMatch("[a", "a", false);
+ assertMatch("[*", "a", false);
+ assertMatch("[*a", "a", false);
+ }
+
+ /**
+ * Single ']' is treated here literally, not as an and of a character group
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBracketsUnmatched2() throws Exception {
+ assertMatch("*]", "a", false);
+ assertMatch("]a", "a", false);
+ assertMatch("]*", "a", false);
+ assertMatch("]*a", "a", false);
+
+ assertMatch("]", "]", true);
+ assertMatch("]*", "]", true);
+ assertMatch("]*", "]a", true);
+ assertMatch("*]", "]", true);
+ assertMatch("*]", "a]", true);
+ }
+
+ @Test
+ public void testBracketsRandom() throws Exception {
+ assertMatch("[\\]", "[$0+//r4a\\d]", false);
+ assertMatch("[:]]sZX]", "[:]]sZX]", false);
+ assertMatch("[:]]:]]]", "[:]]:]]]", false);
}
@Test
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 f972828bc6..e354c7114c 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
@@ -141,9 +141,7 @@ public class Strings {
private static boolean isComplexWildcard(String pattern) {
int idx1 = pattern.indexOf('[');
if (idx1 != -1) {
- int idx2 = pattern.indexOf(']', idx1);
- if (idx2 > idx1)
- return true;
+ return true;
}
if (pattern.indexOf('?') != -1) {
return true;

Back to the top