From c9fca3d0c5cb8f759f8b47c3880f0a7bdd857e62 Mon Sep 17 00:00:00 2001 From: Panagiotis Date: Sat, 15 Jul 2023 04:25:14 +0300 Subject: [PATCH] Fixed case sensitivity on label usage of reserved keyword and added regression tests. Fixed the case when a label was assigned a name of a reserved keyword, resulting in the label being lowercase regardless of the user input. Signed-off-by: Panagiotis Foliadis --- regress/expected/cypher_create.out | 33 +++++++++++++++++++++++++++++- regress/sql/cypher_create.sql | 18 ++++++++++++++++ src/backend/parser/cypher_parser.c | 3 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/regress/expected/cypher_create.out b/regress/expected/cypher_create.out index 9e5b1a240..91b95d39f 100644 --- a/regress/expected/cypher_create.out +++ b/regress/expected/cypher_create.out @@ -765,13 +765,41 @@ $$) as (a agtype); ERROR: variable e already exists LINE 3: CREATE (p)-[e:new]->(a) ^ +-- Validate usage of keywords as labels is supported and case sensitive +SELECT * FROM cypher('cypher_create', $$ + CREATE (a:CREATE) + RETURN a +$$) as (a agtype); + a +----------------------------------------------------------------------- + {"id": 5348024557502465, "label": "CREATE", "properties": {}}::vertex +(1 row) + +SELECT * FROM cypher('cypher_create', $$ + CREATE (a:create) + RETURN a +$$) as (a agtype); + a +----------------------------------------------------------------------- + {"id": 5629499534213121, "label": "create", "properties": {}}::vertex +(1 row) + +SELECT * FROM cypher('cypher_create', $$ + CREATE (a:CrEaTe) + RETURN a +$$) as (a agtype); + a +----------------------------------------------------------------------- + {"id": 5910974510923777, "label": "CrEaTe", "properties": {}}::vertex +(1 row) + -- -- Clean up -- DROP TABLE simple_path; DROP FUNCTION create_test; SELECT drop_graph('cypher_create', true); -NOTICE: drop cascades to 16 other objects +NOTICE: drop cascades to 19 other objects DETAIL: drop cascades to table cypher_create._ag_label_vertex drop cascades to table cypher_create._ag_label_edge drop cascades to table cypher_create.v @@ -788,6 +816,9 @@ drop cascades to table cypher_create."Part" drop cascades to table cypher_create.new drop cascades to table cypher_create.node drop cascades to table cypher_create.n1 +drop cascades to table cypher_create."CREATE" +drop cascades to table cypher_create."create" +drop cascades to table cypher_create."CrEaTe" NOTICE: graph "cypher_create" has been dropped drop_graph ------------ diff --git a/regress/sql/cypher_create.sql b/regress/sql/cypher_create.sql index dd9506982..8c9ac899a 100644 --- a/regress/sql/cypher_create.sql +++ b/regress/sql/cypher_create.sql @@ -385,6 +385,24 @@ SELECT * FROM cypher('cypher_create', $$ CREATE (p)-[e:new]->(a) $$) as (a agtype); + +-- Validate usage of keywords as labels is supported and case sensitive + +SELECT * FROM cypher('cypher_create', $$ + CREATE (a:CREATE) + RETURN a +$$) as (a agtype); + +SELECT * FROM cypher('cypher_create', $$ + CREATE (a:create) + RETURN a +$$) as (a agtype); + +SELECT * FROM cypher('cypher_create', $$ + CREATE (a:CrEaTe) + RETURN a +$$) as (a agtype); + -- -- Clean up -- diff --git a/src/backend/parser/cypher_parser.c b/src/backend/parser/cypher_parser.c index c6a95d398..487f5607d 100644 --- a/src/backend/parser/cypher_parser.c +++ b/src/backend/parser/cypher_parser.c @@ -77,6 +77,9 @@ int cypher_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, ag_scanner_t scanner) * case sensitivity */ lvalp->keyword = GetScanKeyword(kwnum, &CypherKeyword); + ident = pstrdup(token.value.s); + truncate_identifier(ident, strlen(ident), true); + lvalp->string = ident; *llocp = token.location; return CypherKeywordTokens[kwnum]; }