Browse Source

Fixed bug (and added unit test) where a path that ended with a dot (.) would throw an IndexOutOfBoundsException.

pull/5/head
Matt Bishop 13 years ago
parent
commit
13f3adfbde
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java
  2. 7
      json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java

2
json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java

@ -84,7 +84,7 @@ public class PathTokenizer implements Iterable<PathToken> {
case '.': case '.':
poll(); poll();
if (peek() == '.') { if (!isEmpty() && peek() == '.') {
poll(); poll();
fragments.add(".."); fragments.add("..");

7
json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java

@ -78,6 +78,13 @@ public class SplitPathFragmentsTest {
assertPath("$..book[ ?(@.price<10)]", hasItems("$", "..", "book", "[?(@.price<10)]")); assertPath("$..book[ ?(@.price<10)]", hasItems("$", "..", "book", "[?(@.price<10)]"));
} }
@Test
public void dot_ending_ignored() throws Exception {
assertPath("$..book['something'].", hasItems("$", "..", "something"));
}
@Test @Test
public void invalid_path_throws_exception() throws Exception { public void invalid_path_throws_exception() throws Exception {
assertPathInvalid("$...*"); assertPathInvalid("$...*");

Loading…
Cancel
Save