From aea51a5cb6bed405610bf33cc7f143973321e4ee Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Thu, 9 Jul 2020 10:41:27 +0800 Subject: [PATCH] Don't allow label as expression. It's not a value. (#116) * Don't allow label as expression. It's not a value. * Add the name label with ``. Co-authored-by: dutor <440396+dutor@users.noreply.github.com> --- src/parser/parser.yy | 4 ---- src/parser/test/ParserTest.cpp | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/parser/parser.yy b/src/parser/parser.yy index e8b422e2..821852f2 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -359,10 +359,6 @@ base_expression | BOOL { $$ = new ConstantExpression($1); } - | name_label { - $$ = new ConstantExpression(*$1); - delete $1; - } | KW_NULL { $$ = new ConstantExpression(NullType::__NULL__); } diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index 6cab1305..7b1fc686 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -1624,7 +1624,7 @@ TEST(Parser, ConfigOperation) { } { GQLParser parser; - std::string query = "UPDATE CONFIGS storage:name=value"; + std::string query = "UPDATE CONFIGS storage:name=\"value\""; auto result = parser.parse(query); ASSERT_TRUE(result.ok()) << result.status(); } @@ -2020,4 +2020,21 @@ TEST(Parser, UseReservedKeyword) { ASSERT_TRUE(result.ok()); } } + +TEST(Parser, IssueLabelAsExpression) { + // name label is not a valid expression, it's not value + { + GQLParser parser; + std::string query = "INSERT VERTEX person(name) VALUES \"1\":(name_label)"; + auto result = parser.parse(query); + ASSERT_FALSE(result.ok()); + } + { + GQLParser parser; + std::string query = "INSERT VERTEX person(name) VALUES \"1\":(`name_label`)"; + auto result = parser.parse(query); + ASSERT_FALSE(result.ok()); + } +} + } // namespace nebula -- GitLab