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>
This commit is contained in:
commit
32775124d1
|
@ -382,6 +382,39 @@ public void testGetters() {
|
|||
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.
|
||||
|
|
|
@ -378,4 +378,12 @@ public void testDirectoryMatch() throws Exception {
|
|||
writeTrashFile(".gitattributes", "new/ bar\n");
|
||||
assertSameAsCGit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBracketsInGroup() throws Exception {
|
||||
createFiles("[", "]", "[]", "][", "[[]", "[]]", "[[]]");
|
||||
writeTrashFile(".gitattributes", "[[]] bar1\n" + "[\\[]] bar2\n"
|
||||
+ "[[\\]] bar3\n" + "[\\[\\]] bar4\n");
|
||||
assertSameAsCGit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,4 +241,31 @@ public void testDirectoryMatchSubRecursiveBacktrack5() throws Exception {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -369,7 +369,10 @@ && isLetter(lookAhead(pattern, i)))
|
|||
|
||||
case '[':
|
||||
if (in_brackets > 0) {
|
||||
sb.append('\\').append('[');
|
||||
if (!seenEscape) {
|
||||
sb.append('\\');
|
||||
}
|
||||
sb.append('[');
|
||||
ignoreLastBracket = true;
|
||||
} else {
|
||||
if (!seenEscape) {
|
||||
|
|
Loading…
Reference in New Issue