summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2017-12-23 00:36:45 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2017-12-23 00:36:54 +0100
commit32775124d1653a6cecd5bc9bda907cd146d87a06 (patch)
treea0589db15ae8f26b5fb5167baca15b4e2d656301
parent5db26bc399d2ff2b913867343f59e5b2d66cfab2 (diff)
parent279eaf069004b8dca523f1ecb231c1df02ac9031 (diff)
downloadjgit-32775124d1653a6cecd5bc9bda907cd146d87a06.tar.gz
jgit-32775124d1653a6cecd5bc9bda907cd146d87a06.zip
Merge branch 'stable-4.9'
* stable-4.9: Strings#convertGlob: fix escaping of patterns like [\[]. Change-Id: I18d55537002b3153db35f8a6b60f2f5317d17248 Signed-off-by: Matthias Sohn <matthias.sohn@sap.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 05484ab671..196c4f7d9c 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 4d33395d4f..9b255b41c3 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
@@ -369,7 +369,10 @@ public class Strings {
case '[':
if (in_brackets > 0) {
- sb.append('\\').append('[');
+ if (!seenEscape) {
+ sb.append('\\');
+ }
+ sb.append('[');
ignoreLastBracket = true;
} else {
if (!seenEscape) {