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--;
}
int mem = ' ';
int mem = -1;
int curr = start;
boolean inProp = false;
int openSquareBracket = 0;
@ -317,6 +317,13 @@ public class PathCompiler {
}
}
break;
case '\\':
if (mem == '\\') { // escaped backslash, skip it
mem = -1;
curr++;
continue;
}
break;
case '\'':
if(mem == '\\') {
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");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_escaped_backslash_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"it\\\",\n"
+ " \"message\": \"it\\\\\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
// message: it\ -> (after json escaping) -> "it\\" -> (after java escaping) -> "\"it\\\\\""
List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message");

Loading…
Cancel
Save