Skip to content

Commit

Permalink
Fixed partial metapath parsing, which allowed invalid metapaths to be…
Browse files Browse the repository at this point in the history
… used if the first part was seen as valid. Fixes #258 (#260)
  • Loading branch information
david-waltermire authored Nov 22, 2024
1 parent be910a9 commit 0cd0f75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void sync(Parser recognizer) {
}
});

ParseTree tree = ObjectUtils.notNull(parser.expr());
ParseTree tree = ObjectUtils.notNull(parser.metapath());

if (LOGGER.isDebugEnabled()) {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected <T extends RuleContext> R delegateToChild(@NonNull T ctx) {
@Override
public R visitMetapath(MetapathContext ctx) {
assert ctx != null;
return delegateToChild(ctx);
return ctx.expr().accept(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import io.hosuaby.inject.resources.junit.jupiter.GivenTextResource;
import io.hosuaby.inject.resources.junit.jupiter.TestWithResources;

Expand Down Expand Up @@ -71,4 +73,12 @@ void test() {
assertEquals(1, result.size(), "unexpected size");
assertEquals(true, ((IBooleanItem) result.getValue().iterator().next()).toBoolean(), "unexpected result");
}

@Test
void testMalformedIf() throws IOException {
StaticMetapathException ex = assertThrows(StaticMetapathException.class, () -> {
MetapathExpression.compile("if 'a' = '1.1.2' then true() else false()");
});
assertEquals(StaticMetapathException.INVALID_PATH_GRAMMAR, ex.getCode());
}
}

0 comments on commit 0cd0f75

Please sign in to comment.