Skip to content

Commit

Permalink
Fix issues 400, 482, 487: Allow comma in the quoted string (#747)
Browse files Browse the repository at this point in the history
Co-authored-by: Leonid Malikov <leonid@percival.co.uk>
  • Loading branch information
greek1979 and Leonid Malikov committed Nov 9, 2021
1 parent 36db5f8 commit 39c7904
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Expand Up @@ -612,7 +612,7 @@ private boolean readBracketPropertyToken(PathTokenAppender appender) {
inProperty = true;
lastSignificantWasComma = false;
}
} else if (c == COMMA){
} else if (c == COMMA && !inProperty) {
if (lastSignificantWasComma){
fail("Found empty property at index "+readPosition);
}
Expand Down
26 changes: 26 additions & 0 deletions 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"));
}
}

0 comments on commit 39c7904

Please sign in to comment.