Browse Source

semantic of PathToken.isUpstreamDefinite changed: current token is not an upstream of itself

pull/142/head
Alexey Makeyev 9 years ago
parent
commit
1d259d1857
  1. 17
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java
  2. 2
      json-path/src/test/java/com/jayway/jsonpath/PathTokenTest.java

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

@ -43,6 +43,10 @@ public abstract class PathToken {
String evalPath = Utils.concat(currentPath, "['", property, "']");
Object propertyVal = readObjectProperty(property, model, ctx);
if(propertyVal == JsonProvider.UNDEFINED){
// Conditions below heavily depend on current token type (and its logic) and are not "universal",
// so this code is quite dangerous. Better safe than sorry.
assert this instanceof PropertyPathToken : "only PropertyPathToken is supported";
if(isLeaf()) {
if(ctx.options().contains(Option.DEFAULT_PATH_LEAF_TO_NULL)){
propertyVal = null;
@ -148,16 +152,11 @@ public abstract class PathToken {
return prev == null;
}
public boolean isUpstreamDefinite(){
if(upstreamDefinite != null){
return upstreamDefinite.booleanValue();
}
boolean isUpstreamDefinite = isTokenDefinite();
if (isUpstreamDefinite && !isRoot()) {
isUpstreamDefinite = prev.isUpstreamDefinite();
public boolean isUpstreamDefinite() {
if (upstreamDefinite == null) {
upstreamDefinite = isRoot() || prev.isTokenDefinite() && prev.isUpstreamDefinite();
}
upstreamDefinite = isUpstreamDefinite;
return isUpstreamDefinite;
return upstreamDefinite;
}
public int getTokenCount() {

2
json-path/src/test/java/com/jayway/jsonpath/PathTokenTest.java

@ -30,7 +30,7 @@ public class PathTokenTest extends BaseTest {
public void is_upstream_definite_in_complex_case() {
assertThat(makePathReturningTail(makePPT("foo"), makePPT("bar"), makePPT("baz")).isUpstreamDefinite()).isTrue();
assertThat(makePathReturningTail(makePPT("foo"), new WildcardPathToken()).isUpstreamDefinite()).isFalse();
assertThat(makePathReturningTail(makePPT("foo"), new WildcardPathToken()).isUpstreamDefinite()).isTrue();
assertThat(makePathReturningTail(new WildcardPathToken(), makePPT("bar"), makePPT("baz")).isUpstreamDefinite()).isFalse();
}

Loading…
Cancel
Save