Disallow keywords as symbolic names

Reviewers: teon.banek, buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D497
This commit is contained in:
Mislav Bradac 2017-06-20 11:55:24 +02:00
parent bed62c4f8b
commit b6ecc5631f
2 changed files with 25 additions and 1 deletions

View File

@ -332,7 +332,14 @@ antlrcpp::Any CypherMainVisitor::visitSymbolicName(
}
return name;
}
return std::string(ctx->getText());
if (ctx->UnescapedSymbolicName() || ctx->HexLetter()) {
return std::string(ctx->getText());
}
// Symbolic names are case sensitive. Since StrippedQuery lowercases all
// keywords there is no way to differentiate between differently cased
// symbolic names if they are equal to a keyword.
throw SemanticException(
fmt::format("Symbolic name can't be keyword {}", ctx->getText()));
}
antlrcpp::Any CypherMainVisitor::visitPattern(

View File

@ -143,6 +143,23 @@ TYPED_TEST(CypherMainVisitorTest, EscapedLabel) {
ElementsAre(ast_generator.db_accessor_->label("l-$\"'ab`e``l")));
}
TYPED_TEST(CypherMainVisitorTest, KeywordLabel) {
ASSERT_THROW(TypeParam("RETURN n:DEletE"), SemanticException);
}
TYPED_TEST(CypherMainVisitorTest, HexLetterLabel) {
TypeParam ast_generator("RETURN n:a");
auto *query = ast_generator.query_;
ASSERT_EQ(query->clauses_.size(), 1U);
auto *return_clause = dynamic_cast<Return *>(query->clauses_[0]);
auto *labels_test = dynamic_cast<LabelsTest *>(
return_clause->body_.named_expressions[0]->expression_);
auto identifier = dynamic_cast<Identifier *>(labels_test->expression_);
EXPECT_EQ(identifier->name_, "n");
ASSERT_THAT(labels_test->labels_,
ElementsAre(ast_generator.db_accessor_->label("a")));
}
TYPED_TEST(CypherMainVisitorTest, ReturnNoDistinctNoBagSemantics) {
TypeParam ast_generator("RETURN x");
auto *query = ast_generator.query_;