From 13f3adfbde7363c68bca6062fbe5f806db616b42 Mon Sep 17 00:00:00 2001 From: Matt Bishop Date: Tue, 28 Feb 2012 17:12:39 -0800 Subject: [PATCH] Fixed bug (and added unit test) where a path that ended with a dot (.) would throw an IndexOutOfBoundsException. --- .../java/com/jayway/jsonpath/reader/PathTokenizer.java | 2 +- .../java/com/jayway/jsonpath/SplitPathFragmentsTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java b/json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java index e1fa31f8..cc7a7428 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java +++ b/json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java @@ -84,7 +84,7 @@ public class PathTokenizer implements Iterable { case '.': poll(); - if (peek() == '.') { + if (!isEmpty() && peek() == '.') { poll(); fragments.add(".."); diff --git a/json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java b/json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java index b1d33e7c..910f6bc3 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java +++ b/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)]")); } + @Test + public void dot_ending_ignored() throws Exception { + + assertPath("$..book['something'].", hasItems("$", "..", "something")); + + } + @Test public void invalid_path_throws_exception() throws Exception { assertPathInvalid("$...*");