Browse Source

fix for escaped backslash in property inside predicate

pull/142/head
Alexey Makeyev 9 years ago
parent
commit
97db5795bd
  1. 9
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java
  2. 4
      json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java

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

@ -292,7 +292,7 @@ public class PathCompiler {
start--; start--;
} }
int mem = ' '; int mem = -1;
int curr = start; int curr = start;
boolean inProp = false; boolean inProp = false;
int openSquareBracket = 0; int openSquareBracket = 0;
@ -317,6 +317,13 @@ public class PathCompiler {
} }
} }
break; break;
case '\\':
if (mem == '\\') { // escaped backslash, skip it
mem = -1;
curr++;
continue;
}
break;
case '\'': case '\'':
if(mem == '\\') { if(mem == '\\') {
break; break;

4
json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java

@ -25,17 +25,17 @@ public class PredicateTest extends BaseTest {
assertThat(reader.read("$.store.book[?].isbn", List.class, booksWithISBN)).containsOnly("0-395-19395-8", "0-553-21311-3"); assertThat(reader.read("$.store.book[?].isbn", List.class, booksWithISBN)).containsOnly("0-395-19395-8", "0-553-21311-3");
} }
@Ignore("not ready yet (requires compiler reimplementation)")
@Test @Test
public void issue_predicate_can_have_escaped_backslash_in_prop() { public void issue_predicate_can_have_escaped_backslash_in_prop() {
String json = "{\n" String json = "{\n"
+ " \"logs\": [\n" + " \"logs\": [\n"
+ " {\n" + " {\n"
+ " \"message\": \"it\\\",\n" + " \"message\": \"it\\\\\",\n"
+ " \"id\": 2\n" + " \"id\": 2\n"
+ " }\n" + " }\n"
+ " ]\n" + " ]\n"
+ "}"; + "}";
// message: it\ -> (after json escaping) -> "it\\" -> (after java escaping) -> "\"it\\\\\""
List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message"); List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message");

Loading…
Cancel
Save