Merge "[ignore rules] fix for handling unmatched '[' brackets"
This commit is contained in:
commit
0baf81a191
|
@ -54,6 +54,7 @@ public class FastIgnoreRuleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleCharClass() {
|
public void testSimpleCharClass() {
|
||||||
|
assertMatched("][a]", "]a");
|
||||||
assertMatched("[a]", "a");
|
assertMatched("[a]", "a");
|
||||||
assertMatched("][a]", "]a");
|
assertMatched("][a]", "]a");
|
||||||
assertMatched("[a]", "a/");
|
assertMatched("[a]", "a/");
|
||||||
|
|
|
@ -768,7 +768,7 @@ public void testSpecialGroupCase8() throws Exception {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpecialGroupCase9() throws Exception {
|
public void testSpecialGroupCase9() throws Exception {
|
||||||
assertMatch("][", "][", true);
|
assertMatch("][", "][", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -968,6 +968,59 @@ public void testBrackets() throws Exception {
|
||||||
assertMatch("[a{}()b][a{}()b]?[a{}()b][a{}()b]", "{}x()", true);
|
assertMatch("[a{}()b][a{}()b]?[a{}()b][a{}()b]", "{}x()", true);
|
||||||
assertMatch("x*{x}3", "xa{x}3", true);
|
assertMatch("x*{x}3", "xa{x}3", true);
|
||||||
assertMatch("a*{x}3", "axxx", false);
|
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
|
@Test
|
||||||
|
|
|
@ -141,9 +141,7 @@ static boolean isWildCard(String pattern) {
|
||||||
private static boolean isComplexWildcard(String pattern) {
|
private static boolean isComplexWildcard(String pattern) {
|
||||||
int idx1 = pattern.indexOf('[');
|
int idx1 = pattern.indexOf('[');
|
||||||
if (idx1 != -1) {
|
if (idx1 != -1) {
|
||||||
int idx2 = pattern.indexOf(']', idx1);
|
return true;
|
||||||
if (idx2 > idx1)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (pattern.indexOf('?') != -1) {
|
if (pattern.indexOf('?') != -1) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue