Browse Source

Fix issues 400, 482, 487: Allow comma in the quoted string (#747)

Co-authored-by: Leonid Malikov <leonid@percival.co.uk>
pull/469/head
Leonid 3 years ago committed by GitHub
parent
commit
39c7904e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/path/PathCompiler.java
  2. 26
      json-path/src/test/java/com/jayway/jsonpath/Issue_487.java

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

@ -612,7 +612,7 @@ public class PathCompiler {
inProperty = true;
lastSignificantWasComma = false;
}
} else if (c == COMMA){
} else if (c == COMMA && !inProperty) {
if (lastSignificantWasComma){
fail("Found empty property at index "+readPosition);
}

26
json-path/src/test/java/com/jayway/jsonpath/Issue_487.java

@ -0,0 +1,26 @@
package com.jayway.jsonpath;
import org.junit.Test;
public class Issue_487 {
public static final Configuration jsonConf = Configuration.defaultConfiguration();
@Test//(expected = InvalidPathException.class)
public void test_read_with_comma_1(){ // originally throws InvalidPathException
DocumentContext dc = JsonPath.using(jsonConf)
.parse("{ \"key,\" : \"value\" }");
Object ans = dc.read(JsonPath.compile("$['key,']"));
//System.out.println(ans);
assert(ans.toString().equals("value"));
}
@Test
public void test_read_with_comma_2(){ // originally passed
DocumentContext dc = JsonPath.using(jsonConf)
.parse("{ \"key,\" : \"value\" }");
Object ans = dc.read(JsonPath.compile("$['key\\,']"));
//System.out.println(ans);
assert(ans.toString().equals("value"));
}
}
Loading…
Cancel
Save