Skip to content

Commit

Permalink
Fix the issue 629 and add two testcases (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdmms1 committed Nov 4, 2021
1 parent 8e8fc14 commit fcf8bf6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ else if (c == OPEN_PARENTHESIS) {

List<Parameter> functionParameters = null;
if (isFunction) {
int parenthesis_count = 1;
for(int i = readPosition + 1; i < path.length(); i++){
if (path.charAt(i) == CLOSE_PARENTHESIS)
parenthesis_count--;
else if (path.charAt(i) == OPEN_PARENTHESIS)
parenthesis_count++;
if (parenthesis_count == 0)
break;
}

if (parenthesis_count != 0){
String functionName = path.subSequence(startPosition, endPosition).toString();
throw new InvalidPathException("Arguments to function: '" + functionName + "' are not closed properly.");
}

if (path.inBounds(readPosition+1)) {
// read the next token to determine if we have a simple no-args function call
char c = path.charAt(readPosition + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.jayway.jsonpath.internal.function;

import com.jayway.jsonpath.JsonPath;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertTrue;

public class Issue629 {
@Test
public void testUncloseParenthesis() throws IOException {
try {
JsonPath jsonPath = JsonPath.compile("$.A.B.C.D(");
assert(false);
}
catch (Exception e) {
assertTrue(e.getMessage().startsWith("Arguments to function:"));
}
}

@Test
public void testUncloseParenthesisWithNestedCall() throws IOException {
try {
JsonPath jsonPath = JsonPath.compile("$.A.B.C.sum(D()");
assert(false);
}
catch (Exception e) {
assertTrue(e.getMessage().startsWith("Arguments to function:"));
}
}
}

0 comments on commit fcf8bf6

Please sign in to comment.