From 6f770d568568d6561008e24f59d1c9ab702ba196 Mon Sep 17 00:00:00 2001 From: Stephen Mallette Date: Thu, 14 Nov 2024 17:16:15 -0500 Subject: [PATCH] Stopped grammar from parsing child traversals spawned from g This was already disallowed in Java, so it follows that it should be prevented even earlier by the parser. CTR --- CHANGELOG.asciidoc | 5 +++-- .../language/grammar/GremlinQueryParserTest.java | 12 ++++++++++++ gremlin-language/src/main/antlr4/Gremlin.g4 | 3 +-- .../src/test/resources/incorrect-traversals.txt | 4 +++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 2c847875be4..557aec03729 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -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) diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java index 9b67393e663..10709f3ebc5 100644 --- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java +++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/language/grammar/GremlinQueryParserTest.java @@ -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; + } + } } diff --git a/gremlin-language/src/main/antlr4/Gremlin.g4 b/gremlin-language/src/main/antlr4/Gremlin.g4 index 7268797beba..de39307566a 100644 --- a/gremlin-language/src/main/antlr4/Gremlin.g4 +++ b/gremlin-language/src/main/antlr4/Gremlin.g4 @@ -167,8 +167,7 @@ chainedParentOfGraphTraversal ; nestedTraversal - : rootTraversal - | chainedTraversal + : chainedTraversal | ANON_TRAVERSAL_ROOT DOT chainedTraversal ; diff --git a/gremlin-language/src/test/resources/incorrect-traversals.txt b/gremlin-language/src/test/resources/incorrect-traversals.txt index 340c772c8e6..6886b21011c 100644 --- a/gremlin-language/src/test/resources/incorrect-traversals.txt +++ b/gremlin-language/src/test/resources/incorrect-traversals.txt @@ -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]) \ No newline at end of file +g.mergeE(["weight": 0.5, Direction.in: 1]) +g.addE('knows').from(g.V(1)) +g.addE('knows').from(g.V(1).next()) \ No newline at end of file