Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable DOT in label. #4194

Merged
merged 7 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/graph/context/Iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ PropIter::PropIter(std::shared_ptr<Value> value, bool checkMemory)
auto& ds = value->getDataSet();
auto status = makeDataSetIndex(ds);
if (UNLIKELY(!status.ok())) {
LOG(ERROR) << status;
DLOG(FATAL) << status;
clear();
return;
}
Expand Down
8 changes: 7 additions & 1 deletion src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}*
::strncpy(sbuf() + sbufPos_, yytext, yyleng);
sbufPos_ += yyleng;
}
<LB_STR>[^\\\n\`]+ {
<LB_STR>[^\\\n\`\.]+ {
makeSpaceForString(yyleng);
::strncpy(sbuf() + sbufPos_, yytext, yyleng);
sbufPos_ += yyleng;
Expand Down Expand Up @@ -505,6 +505,12 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}*
// but without this, it somehow triggers the `nodefault' warning of flex.
yyterminate();
}
/* We use DOT to access property of entities, so it's meta character in this language.
* Disable DOT in label to avoid mistakes in system and confusing to user.
*/
<LB_STR>\. {
throw GraphParser::syntax_error(*yylloc, "Don't allow DOT in label:");
}

[ \r\t] { }
\n {
Expand Down
26 changes: 13 additions & 13 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2806,12 +2806,12 @@ TEST_F(ParserTest, Zone) {
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "ADD HOSTS 127.0.0.1:8989 INTO ZONE `default_zone_127.0.0.1_8988`";
std::string query = "ADD HOSTS 127.0.0.1:8989 INTO ZONE `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "ADD HOSTS 127.0.0.1:8989 INTO NEW ZONE `default_zone_127.0.0.1_8988`";
std::string query = "ADD HOSTS 127.0.0.1:8989 INTO NEW ZONE `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
Expand All @@ -2828,19 +2828,19 @@ TEST_F(ParserTest, Zone) {
{
std::string query =
"ADD HOSTS 127.0.0.1:8988,127.0.0.1:8989 INTO ZONE"
" `default_zone_127.0.0.1_8988`";
" `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query =
"ADD HOSTS 127.0.0.1:8988,127.0.0.1:8989 INTO NEW ZONE"
" `default_zone_127.0.0.1_8988`";
" `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "DESC ZONE `default_zone_127.0.0.1_8988`";
std::string query = "DESC ZONE `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
Expand All @@ -2855,7 +2855,7 @@ TEST_F(ParserTest, Zone) {
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "DESCRIBE ZONE `default_zone_127.0.0.1_8988`";
std::string query = "DESCRIBE ZONE `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
Expand All @@ -2865,7 +2865,7 @@ TEST_F(ParserTest, Zone) {
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "DROP ZONE `default_zone_127.0.0.1_8988`";
std::string query = "DROP ZONE `default_zone_127_0_0_1_8988`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
Expand All @@ -2881,20 +2881,20 @@ TEST_F(ParserTest, Zone) {
}
{
std::string query =
"MERGE ZONE `default_zone_127.0.0.1_8988`,`default_zone_127.0.0.1_8989`"
"MERGE ZONE `default_zone_127_0_0_1_8988`,`default_zone_127_0_0_1_8989`"
"INTO `zone_1`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query =
"MERGE ZONE `default_zone_127.0.0.1_8988`,`default_zone_127.0.0.1_8989`"
"INTO `default_zone_127.0.0.1_8989`";
"MERGE ZONE `default_zone_127_0_0_1_8988`,`default_zone_127_0_0_1_8989`"
"INTO `default_zone_127_0_0_1_8989`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "RENAME ZONE `default_zone_127.0.0.1_8989` TO `new_name`";
std::string query = "RENAME ZONE `default_zone_127_0_0_1_8989` TO `new_name`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
Expand All @@ -2904,7 +2904,7 @@ TEST_F(ParserTest, Zone) {
ASSERT_TRUE(result.ok()) << result.status();
}
{
std::string query = "RENAME ZONE `default_zone_127.0.0.1_8989` TO `new_name`";
std::string query = "RENAME ZONE `default_zone_127_0_0_1_8989` TO `new_name`";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
Expand Down Expand Up @@ -3317,7 +3317,7 @@ TEST_F(ParserTest, TestNameLabel) {
{
std::string query = "CREATE TAG `person127.0.0.1`(name STRING);";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
}

Expand Down
12 changes: 12 additions & 0 deletions tests/tck/features/schema/Schema.feature
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,15 @@ Feature: Insert string vid of vertex and edge
DROP SPACE issue2009;
"""
Then the execution should be successful

Scenario: Don't allow DOT in schema name
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | FIXED_STRING(20) |
When executing query:
"""
CREATE TAG `tag.prop`()
"""
Then a SyntaxError should be raised at runtime: Don't allow DOT in label: near `.prop`()'