From e90fae1bb78fba93d1a0e21cbc9ae9070099dfa6 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Thu, 21 Apr 2022 14:39:01 +0800 Subject: [PATCH 1/2] Disable DOT in label. --- src/graph/context/Iterator.cpp | 2 +- src/parser/scanner.lex | 7 ++++++- src/parser/test/ParserTest.cpp | 26 ++++++++++++------------ tests/tck/features/schema/Schema.feature | 12 +++++++++++ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/graph/context/Iterator.cpp b/src/graph/context/Iterator.cpp index 2bc009a8a40..3c18ac702f7 100644 --- a/src/graph/context/Iterator.cpp +++ b/src/graph/context/Iterator.cpp @@ -704,7 +704,7 @@ PropIter::PropIter(std::shared_ptr value, bool checkMemory) auto& ds = value->getDataSet(); auto status = makeDataSetIndex(ds); if (UNLIKELY(!status.ok())) { - LOG(ERROR) << status; + DLOG(FATAL) << status; clear(); return; } diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index b0e13b4b978..07943f37ebc 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -441,7 +441,7 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}* ::strncpy(sbuf() + sbufPos_, yytext, yyleng); sbufPos_ += yyleng; } -[^\\\n\`]+ { +[^\\\n\`\.]+ { makeSpaceForString(yyleng); ::strncpy(sbuf() + sbufPos_, yytext, yyleng); sbufPos_ += yyleng; @@ -505,6 +505,11 @@ 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. */ +\. + throw GraphParser::syntax_error(*yylloc, "Don't allow DOT in label:"); + } [ \r\t] { } \n { diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index d25cdd76705..bd7b2d816cd 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } } diff --git a/tests/tck/features/schema/Schema.feature b/tests/tck/features/schema/Schema.feature index af8e2c08eb7..1129401c609 100644 --- a/tests/tck/features/schema/Schema.feature +++ b/tests/tck/features/schema/Schema.feature @@ -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`()' From 8483a4517f3162463d797552b050a9583988bf87 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Thu, 21 Apr 2022 14:47:20 +0800 Subject: [PATCH 2/2] Fix lex comment style. --- src/parser/scanner.lex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index 07943f37ebc..bb9d864f591 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -505,9 +505,10 @@ 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. */ -\. + /* 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. + */ +\. { throw GraphParser::syntax_error(*yylloc, "Don't allow DOT in label:"); }