Skip to content

Commit

Permalink
Stopped grammar from parsing child traversals spawned from g
Browse files Browse the repository at this point in the history
This was already disallowed in Java, so it follows that it should be prevented even earlier by the parser. CTR
  • Loading branch information
spmallette committed Nov 14, 2024
1 parent bf1656f commit 6f770d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
[[release-3-7-4]]
=== TinkerPop 3.7.4 (NOT OFFICIALLY RELEASED YET)
* Add log entry in WsAndHttpChannelizerHandler.
* IdentityRemovalStrategy does not omit IdentityStep if only with RepeatEndStep under RepeatStep.
* Add log entry in `WsAndHttpChannelizerHandler`.
* Changed `IdentityRemovalStrategy` to omit `IdentityStep` if only with `RepeatEndStep` under `RepeatStep`.
* Changed Gremlin grammar to make use of `g` to spawn child traversals a syntax error.
[[release-3-7-3]]
=== TinkerPop 3.7.3 (October 23, 2024)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@ public void shouldParseMultiVariablesWithNoOp() {
assertEquals(g.V(null, null, null).has("name", P.gt(null)).asAdmin().getBytecode(),
t.asAdmin().getBytecode());
}

@Test(expected = GremlinParserException.class)
public void shouldNotParseChildTraversalsSpawnedFromG() {
final GremlinAntlrToJava gremlinAntlrToJava = new GremlinAntlrToJava("g",
EmptyGraph.instance(), __::start, g, VariableResolver.NoVariableResolver.instance());
try {
GremlinQueryParser.parse("g.addE('knows').from(g.V(1))", gremlinAntlrToJava);
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
}
3 changes: 1 addition & 2 deletions gremlin-language/src/main/antlr4/Gremlin.g4
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ chainedParentOfGraphTraversal
;

nestedTraversal
: rootTraversal
| chainedTraversal
: chainedTraversal
| ANON_TRAVERSAL_ROOT DOT chainedTraversal
;

Expand Down
4 changes: 3 additions & 1 deletion gremlin-language/src/test/resources/incorrect-traversals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ g.V('3').dedupe()
g.V().order().bye('code').limit(1)
g.V().horder().by(id)
g.mergeE(["weight": 0.5, Direction.out: 1])
g.mergeE(["weight": 0.5, Direction.in: 1])
g.mergeE(["weight": 0.5, Direction.in: 1])
g.addE('knows').from(g.V(1))
g.addE('knows').from(g.V(1).next())

0 comments on commit 6f770d5

Please sign in to comment.