Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fix multiple nested calls #1011

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ private PathNode readPath() {
int begin = filter.position();

filter.incrementPosition(1); //skip $ and @
int groupParen = 0;
while (filter.inBounds()) {
if (filter.currentChar() == OPEN_SQUARE_BRACKET) {
int closingSquareBracketIndex = filter.indexOfMatchingCloseChar(filter.position(), OPEN_SQUARE_BRACKET, CLOSE_SQUARE_BRACKET, true, false);
Expand All @@ -364,14 +365,31 @@ private PathNode readPath() {
filter.setPosition(closingSquareBracketIndex + 1);
}
}
boolean closingFunctionBracket = (filter.currentChar() == CLOSE_PARENTHESIS && currentCharIsClosingFunctionBracket(begin));
boolean closingLogicalBracket = (filter.currentChar() == CLOSE_PARENTHESIS && !closingFunctionBracket);

if (!filter.inBounds() || isRelationalOperatorChar(filter.currentChar()) || filter.currentChar() == SPACE || closingLogicalBracket) {
break;
if (filter.currentChar() == OPEN_PARENTHESIS) {
groupParen++;
}

if (groupParen == 0) {
boolean closingFunctionBracket = (filter.currentChar() == CLOSE_PARENTHESIS && currentCharIsClosingFunctionBracket(begin));
boolean closingLogicalBracket = (filter.currentChar() == CLOSE_PARENTHESIS && !closingFunctionBracket);

if (!filter.inBounds() || isRelationalOperatorChar(filter.currentChar()) || filter.currentChar() == SPACE || closingLogicalBracket) {
break;
} else {
filter.incrementPosition(1);
}
} else {
if (filter.currentChar() == CLOSE_PARENTHESIS) {
groupParen--;
if (groupParen < 0) {
throw new InvalidPathException("Parentheses does not match in filter " + filter);
}
}
filter.incrementPosition(1);
}


}

boolean shouldExists = !(previousSignificantChar == NOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,11 @@ else if (isPathContext(c)) {
// we've encountered a COMMA do the same
case CLOSE_PARENTHESIS:
groupParen--;
//CS304 Issue link: https://github.com/json-path/JsonPath/issues/620
if (0 > groupParen || priorChar == '(') {
parameter.append(c);
}
case COMMA:
// In this state we've reach the end of a function parameter and we can pass along the parameter string
// to the parser
if ((0 == groupQuote && 0 == groupBrace && 0 == groupBracket
&& ((0 == groupParen && CLOSE_PARENTHESIS == c) || 1 == groupParen))) {
&& ((0 == groupParen && CLOSE_PARENTHESIS == c) || (1 == groupParen && c == COMMA)))) {
endOfStream = (0 == groupParen);

if (null != type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,11 @@ public void escape_pattern_before_literal(Configuration conf) {
public void filter_evaluation_does_not_break_path_evaluation(Configuration conf) {
assertHasOneResult("[{\"s\": \"fo\", \"expected_size\": \"m\"}, {\"s\": \"lo\", \"expected_size\": 2}]", "$[?(@.s size @.expected_size)]", conf);
}

@ParameterizedTest
@MethodSource("configurations")
public void testFilterCallingFunction(Configuration conf) {
assertHasOneResult("[[\"abcdef\"]]", "$[?(@.concat(\"-\") == \"abcdef-\")]", conf);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public void testStringConcat(Configuration conf) {
}


@ParameterizedTest
@MethodSource("configurations")
public void testMultipleCall(Configuration conf) {
verifyTextFunction(conf, "$.concat($.text[0], $.concat( $.concat($.text[3], \"-1\"), $.concat($.text[4], \"-1\")))", "ad-1e-1");
}



@ParameterizedTest
@MethodSource("configurations")
public void testStringAndNumberConcat(Configuration conf) {
Expand Down