From 8a40b0420a902dac2256043d9d3a2ed4184c140f Mon Sep 17 00:00:00 2001 From: Kalle Stenflo Date: Tue, 9 Jun 2015 23:37:11 +0200 Subject: [PATCH] Fixed issue #79. Index out of bounds. --- .../jsonpath/internal/token/PathToken.java | 1 - .../com/jayway/jsonpath/old/IssuesTest.java | 24 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java index 3d1897bc..720728a2 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java @@ -125,7 +125,6 @@ public abstract class PathToken { next().evaluate(evalPath, pathRef, evalHit, ctx); } } catch (IndexOutOfBoundsException e) { - throw new PathNotFoundException("Index out of bounds when evaluating path " + evalPath); } } diff --git a/json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java b/json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java index d798a81a..62e2a70b 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java @@ -602,11 +602,25 @@ public class IssuesTest extends BaseTest { Assert.assertTrue(false); } catch (RuntimeException e){ } - - - } + @Test + public void issue_79() throws Exception { + String json = "{ \n" + + " \"c\": {\n" + + " \"d1\": {\n" + + " \"url\": [ \"url1\", \"url2\" ]\n" + + " },\n" + + " \"d2\": {\n" + + " \"url\": [ \"url3\", \"url4\",\"url5\" ]\n" + + " }\n" + + " }\n" + + "}"; + + List res = JsonPath.read(json, "$.c.*.url[2]"); + + Assertions.assertThat(res).containsExactly("url5"); + } @Test public void issue_97() throws Exception { String json = "{ \"books\": [ " + @@ -629,5 +643,9 @@ public class IssuesTest extends BaseTest { DocumentContext context = JsonPath.using(conf).parse(json); context.delete("$.books[?(@.category == 'reference')]"); + + List categories = context.read("$..category", List.class); + + Assertions.assertThat(categories).containsOnly("fiction"); } }