Browse Source

Fix the issue 629 and add two testcases (#698)

pull/763/head
sdmms1 3 years ago committed by GitHub
parent
commit
fcf8bf6478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java
  2. 32
      json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue629.java

15
json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java

@ -207,6 +207,21 @@ public class PathCompiler {
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);

32
json-path/src/test/java/com/jayway/jsonpath/internal/function/Issue629.java

@ -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:"));
}
}
}
Loading…
Cancel
Save