Browse Source

fix for object property handling in case of Option.SUPPRESS_EXCEPTIONS and indefinite upstream path

pull/142/head
Alexey Makeyev 9 years ago
parent
commit
f013e86fb8
  1. 4
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java
  2. 13
      json-path/src/test/java/com/jayway/jsonpath/OptionsTest.java

4
json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java

@ -57,8 +57,8 @@ public abstract class PathToken {
} }
} else { } else {
if(!isUpstreamDefinite() && if(!isUpstreamDefinite() &&
!ctx.options().contains(Option.REQUIRE_PROPERTIES) && !ctx.options().contains(Option.REQUIRE_PROPERTIES) ||
!ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)){ ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)){
return; return;
} else { } else {
throw new PathNotFoundException("Missing property in path " + evalPath); throw new PathNotFoundException("Missing property in path " + evalPath);

13
json-path/src/test/java/com/jayway/jsonpath/OptionsTest.java

@ -137,4 +137,17 @@ public class OptionsTest extends BaseTest {
} catch (PathNotFoundException pnf){} } catch (PathNotFoundException pnf){}
} }
@Test
public void issue_suppress_exceptions_does_not_break_indefinite_evaluation() {
Configuration conf = Configuration.builder().options(SUPPRESS_EXCEPTIONS).build();
assertThat(using(conf).parse("{\"foo2\": [5]}").read("$..foo2[0]")).asList().containsOnly(5);
assertThat(using(conf).parse("{\"foo\" : {\"foo2\": [5]}}").read("$..foo2[0]")).asList().containsOnly(5);
assertThat(using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo2[0]")).asList().containsOnly(5);
assertThat(using(conf).parse("[null, [{\"foo\" : {\"foo2\": [5]}}]]").read("$..foo.foo2[0]")).asList().containsOnly(5);
assertThat(using(conf).parse("{\"aoo\" : {}, \"foo\" : {\"foo2\": [5]}, \"zoo\" : {}}").read("$[*].foo2[0]")).asList().containsOnly(5);
}
} }

Loading…
Cancel
Save