未验证 提交 eb8db779 编写于 作者: F Felix Schumacher 提交者: GitHub

Only look for PatternFlags after a regular expression (#661)

上级 15354f7f
......@@ -274,17 +274,32 @@ public class FilterCompiler {
}
private int endOfFlags(int position) {
int endIndex = position;
char[] currentChar = new char[1];
while (filter.inBounds(endIndex)) {
currentChar[0] = filter.charAt(endIndex);
if (PatternFlag.parseFlags(currentChar) > 0) {
endIndex++;
continue;
}
break;
}
return endIndex;
}
private PatternNode readPattern() {
int begin = filter.position();
int closingIndex = filter.nextIndexOfUnescaped(PATTERN);
if (closingIndex == -1) {
throw new InvalidPathException("Pattern not closed. Expected " + PATTERN + " in " + filter);
} else {
if(filter.inBounds(closingIndex+1)) {
int equalSignIndex = filter.nextIndexOf('=');
int endIndex = equalSignIndex > closingIndex ? equalSignIndex : filter.nextIndexOfUnescaped(CLOSE_PARENTHESIS);
CharSequence flags = filter.subSequence(closingIndex + 1, endIndex);
closingIndex += flags.length();
if (filter.inBounds(closingIndex+1)) {
int endFlagsIndex = endOfFlags(closingIndex + 1);
if (endFlagsIndex > closingIndex) {
CharSequence flags = filter.subSequence(closingIndex + 1, endFlagsIndex);
closingIndex += flags.length();
}
}
filter.setPosition(closingIndex + 1);
}
......
......@@ -210,6 +210,16 @@ public class InlineFilterTest extends BaseTest {
assertHasOneResult("[\"x\"]", "$[?(@ =~ /\\/|x/)]", conf);
}
@Test
public void escape_pattern_after_literal() {
assertHasOneResult("[\"x\"]", "$[?(@ == \"abc\" || @ =~ /\\/|x/)]", conf);
}
@Test
public void escape_pattern_before_literal() {
assertHasOneResult("[\"x\"]", "$[?(@ =~ /\\/|x/ || @ == \"abc\")]", conf);
}
@Test
public void filter_evaluation_does_not_break_path_evaluation() {
assertHasOneResult("[{\"s\": \"fo\", \"expected_size\": \"m\"}, {\"s\": \"lo\", \"expected_size\": 2}]", "$[?(@.s size @.expected_size)]", conf);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册