Browse Source

number of issues discovered in predicate parsing

And I dont see a quickfix. I suggest reimplementing entire path compilation using context-free grammar approach.
pull/142/head
Alexey Makeyev 9 years ago
parent
commit
5c0dc56722
  1. 104
      json-path/src/test/java/com/jayway/jsonpath/PredicateTest.java

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

@ -1,5 +1,6 @@
package com.jayway.jsonpath;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
@ -23,4 +24,107 @@ 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"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message");
assertThat(result).containsExactly("it\\");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_bracket_in_regex() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"(it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message =~ /\\(it/)].message");
assertThat(result).containsExactly("(it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_and_in_regex() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message =~ /&&|it/)].message");
assertThat(result).containsExactly("it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_and_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"&& it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == '&& it')].message");
assertThat(result).containsExactly("&& it");
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_brackets_must_change_priorities() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message && (@.id == 1 || @.id == 2))].id");
assertThat(result).isEmpty();
result = JsonPath.read(json, "$.logs[?((@.id == 2 || @.id == 1) && @.message)].id");
assertThat(result).isEmpty();
}
@Ignore("not ready yet (requires compiler reimplementation)")
@Test
public void issue_predicate_can_have_square_bracket_in_prop() {
String json = "{\n"
+ " \"logs\": [\n"
+ " {\n"
+ " \"message\": \"] it\",\n"
+ " \"id\": 2\n"
+ " }\n"
+ " ]\n"
+ "}";
List<String> result = JsonPath.read(json, "$.logs[?(@.message == '] it')].message");
assertThat(result).containsExactly("] it");
}
}

Loading…
Cancel
Save