From 6112454b08231f79625ccd3c23fd95e717806550 Mon Sep 17 00:00:00 2001 From: Mislav Bradac Date: Tue, 4 Apr 2017 18:30:10 +0200 Subject: [PATCH] Throw exception on trailing text in query Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D222 --- src/query/frontend/opencypher/grammar/Cypher.g4 | 2 +- tests/unit/cypher_main_visitor.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index 80e808948..880c3e665 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -16,7 +16,7 @@ */ grammar Cypher; -cypher : SP? statement ( SP? ';' )? SP? ; +cypher : SP? statement ( SP? ';' )? SP? EOF ; statement : query ; diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index 67ec4a092..db148c592 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -47,6 +47,10 @@ TEST(CypherMainVisitorTest, SyntaxException) { ASSERT_THROW(AstGenerator("CREATE ()-[*1...2]-()"), SyntaxException); } +TEST(CypherMainVisitorTest, SyntaxExceptionOnTrailingText) { + ASSERT_THROW(AstGenerator("RETURN 2 + 2 mirko"), SyntaxException); +} + TEST(CypherMainVisitorTest, PropertyLookup) { AstGenerator ast_generator("RETURN n.x"); auto *query = ast_generator.query_;