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:
parent
bed62c4f8b
commit
b6ecc5631f
@ -332,8 +332,15 @@ antlrcpp::Any CypherMainVisitor::visitSymbolicName(
|
|||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
if (ctx->UnescapedSymbolicName() || ctx->HexLetter()) {
|
||||||
return std::string(ctx->getText());
|
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(
|
antlrcpp::Any CypherMainVisitor::visitPattern(
|
||||||
CypherParser::PatternContext *ctx) {
|
CypherParser::PatternContext *ctx) {
|
||||||
|
@ -143,6 +143,23 @@ TYPED_TEST(CypherMainVisitorTest, EscapedLabel) {
|
|||||||
ElementsAre(ast_generator.db_accessor_->label("l-$\"'ab`e``l")));
|
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) {
|
TYPED_TEST(CypherMainVisitorTest, ReturnNoDistinctNoBagSemantics) {
|
||||||
TypeParam ast_generator("RETURN x");
|
TypeParam ast_generator("RETURN x");
|
||||||
auto *query = ast_generator.query_;
|
auto *query = ast_generator.query_;
|
||||||
|
Loading…
Reference in New Issue
Block a user