Browse Source

Fixed issue #79. Index out of bounds.

pull/98/head
Kalle Stenflo 10 years ago
parent
commit
8a40b0420a
  1. 1
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java
  2. 20
      json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

1
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); next().evaluate(evalPath, pathRef, evalHit, ctx);
} }
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
throw new PathNotFoundException("Index out of bounds when evaluating path " + evalPath);
} }
} }

20
json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

@ -602,11 +602,25 @@ public class IssuesTest extends BaseTest {
Assert.assertTrue(false); Assert.assertTrue(false);
} catch (RuntimeException e){ } 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<String> res = JsonPath.read(json, "$.c.*.url[2]");
Assertions.assertThat(res).containsExactly("url5");
} }
@Test @Test
public void issue_97() throws Exception { public void issue_97() throws Exception {
String json = "{ \"books\": [ " + String json = "{ \"books\": [ " +
@ -629,5 +643,9 @@ public class IssuesTest extends BaseTest {
DocumentContext context = JsonPath.using(conf).parse(json); DocumentContext context = JsonPath.using(conf).parse(json);
context.delete("$.books[?(@.category == 'reference')]"); context.delete("$.books[?(@.category == 'reference')]");
List<String> categories = context.read("$..category", List.class);
Assertions.assertThat(categories).containsOnly("fiction");
} }
} }

Loading…
Cancel
Save