Properly support special regex characters in ignore rules
Ignore rules should escape $^(){}+| chars if using regular expressions, because they should be treated literally if they aren't part of a character group. Bug: 478055 Change-Id: Ic7276442d7f8f02594b85eae1ef697362e62d3bd Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
This commit is contained in:
parent
79974e20cc
commit
97ef1fe893
|
@ -868,6 +868,84 @@ public void testMultipleEscapedCharacters1() throws Exception {
|
|||
assertMatch("\\]a?c\\*\\[d\\?\\]", "]abc*[d?]", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDollar() throws Exception {
|
||||
assertMatch("$", "$", true);
|
||||
assertMatch("$x", "$x", true);
|
||||
assertMatch("$x", "x$", false);
|
||||
assertMatch("$x", "$", false);
|
||||
|
||||
assertMatch("$x.*", "$x.a", true);
|
||||
assertMatch("*$", "x$", true);
|
||||
assertMatch("*.$", "x.$", true);
|
||||
|
||||
assertMatch("$*x", "$ax", true);
|
||||
assertMatch("x*$", "xa$", true);
|
||||
assertMatch("x*$", "xa", false);
|
||||
assertMatch("[a$b]", "$", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCaret() throws Exception {
|
||||
assertMatch("^", "^", true);
|
||||
assertMatch("^x", "^x", true);
|
||||
assertMatch("^x", "x^", false);
|
||||
assertMatch("^x", "^", false);
|
||||
|
||||
assertMatch("^x.*", "^x.a", true);
|
||||
assertMatch("*^", "x^", true);
|
||||
assertMatch("*.^", "x.^", true);
|
||||
|
||||
assertMatch("x*^", "xa^", true);
|
||||
assertMatch("^*x", "^ax", true);
|
||||
assertMatch("^*x", "ax", false);
|
||||
assertMatch("[a^b]", "^", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlus() throws Exception {
|
||||
assertMatch("+", "+", true);
|
||||
assertMatch("+x", "+x", true);
|
||||
assertMatch("+x", "x+", false);
|
||||
assertMatch("+x", "+", false);
|
||||
assertMatch("x+", "xx", false);
|
||||
|
||||
assertMatch("+x.*", "+x.a", true);
|
||||
assertMatch("*+", "x+", true);
|
||||
assertMatch("*.+", "x.+", true);
|
||||
|
||||
assertMatch("x*+", "xa+", true);
|
||||
assertMatch("+*x", "+ax", true);
|
||||
assertMatch("+*x", "ax", false);
|
||||
assertMatch("[a+b]", "+", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPipe() throws Exception {
|
||||
assertMatch("|", "|", true);
|
||||
assertMatch("|x", "|x", true);
|
||||
assertMatch("|x", "x|", false);
|
||||
assertMatch("|x", "|", false);
|
||||
assertMatch("x|x", "xx", false);
|
||||
|
||||
assertMatch("x|x.*", "x|x.a", true);
|
||||
assertMatch("*|", "x|", true);
|
||||
assertMatch("*.|", "x.|", true);
|
||||
|
||||
assertMatch("x*|a", "xb|a", true);
|
||||
assertMatch("b|*x", "b|ax", true);
|
||||
assertMatch("b|*x", "ax", false);
|
||||
assertMatch("[a|b]", "|", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrackets() throws Exception {
|
||||
assertMatch("{}*()", "{}x()", true);
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilePathSimpleCase() throws Exception {
|
||||
assertFileNameMatch("a/b", "a/b", true);
|
||||
|
|
|
@ -247,7 +247,7 @@ static Pattern convertGlob(String pattern) throws InvalidPatternException {
|
|||
char[] charClass = new char[6];
|
||||
|
||||
for (int i = 0; i < pattern.length(); i++) {
|
||||
char c = pattern.charAt(i);
|
||||
final char c = pattern.charAt(i);
|
||||
switch (c) {
|
||||
|
||||
case '*':
|
||||
|
@ -257,6 +257,20 @@ static Pattern convertGlob(String pattern) throws InvalidPatternException {
|
|||
sb.append('.').append(c);
|
||||
break;
|
||||
|
||||
case '(': // fall-through
|
||||
case ')': // fall-through
|
||||
case '{': // fall-through
|
||||
case '}': // fall-through
|
||||
case '+': // fall-through
|
||||
case '$': // fall-through
|
||||
case '^': // fall-through
|
||||
case '|':
|
||||
if (seenEscape || in_brackets > 0)
|
||||
sb.append(c);
|
||||
else
|
||||
sb.append('\\').append(c);
|
||||
break;
|
||||
|
||||
case '.':
|
||||
if (seenEscape)
|
||||
sb.append(c);
|
||||
|
|
Loading…
Reference in New Issue