From cdf8b41ff9853293f9097d0c7e6bc96f0e24c2e3 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Thu, 12 Dec 2024 15:37:50 +0100 Subject: [PATCH] fix: $ must be escaped in future Cypher versions. --- .../src/main/java/module-info.java | 37 ------------------- .../cypherdsl/parser/CypherDslASTFactory.java | 1 - .../parser/CypherDslASTFactoryTest.java | 2 +- .../cypherdsl/parser/CypherParserTest.java | 5 +++ .../support/schema_name/SchemaNames.java | 5 ++- 5 files changed, 9 insertions(+), 41 deletions(-) delete mode 100644 neo4j-cypher-dsl-parser/src/main/java/module-info.java diff --git a/neo4j-cypher-dsl-parser/src/main/java/module-info.java b/neo4j-cypher-dsl-parser/src/main/java/module-info.java deleted file mode 100644 index 03ff9118f1..0000000000 --- a/neo4j-cypher-dsl-parser/src/main/java/module-info.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019-2024 "Neo4j," - * Neo4j Sweden AB [https://neo4j.com] - * - * This file is part of Neo4j. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Michael J. Simons - * @since 2023.0.0 - */ -@SuppressWarnings( {"requires-automatic"}) // Neo4j Cypher Parser -module org.neo4j.cypherdsl.parser { - - requires static org.jetbrains.annotations; - - requires transitive org.apiguardian.api; - requires transitive org.neo4j.cypherdsl.core; - - requires org.neo4j.cypher.internal.parser; - requires org.neo4j.cypher.internal.parser.javacc; - requires org.neo4j.cypher.internal.ast.factory; - requires org.neo4j.gql.status; - - exports org.neo4j.cypherdsl.parser; -} diff --git a/neo4j-cypher-dsl-parser/src/main/java/org/neo4j/cypherdsl/parser/CypherDslASTFactory.java b/neo4j-cypher-dsl-parser/src/main/java/org/neo4j/cypherdsl/parser/CypherDslASTFactory.java index 721d994318..8ee1049985 100644 --- a/neo4j-cypher-dsl-parser/src/main/java/org/neo4j/cypherdsl/parser/CypherDslASTFactory.java +++ b/neo4j-cypher-dsl-parser/src/main/java/org/neo4j/cypherdsl/parser/CypherDslASTFactory.java @@ -1059,7 +1059,6 @@ public Statement showAliases(InputPosition p, DatabaseName aliasName, Clause yie @Override public void addDeprecatedIdentifierUnicodeNotification(InputPosition p, Character character, String identifier) { - throw new UnsupportedOperationException(); } @Override diff --git a/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherDslASTFactoryTest.java b/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherDslASTFactoryTest.java index 2eb8cf63c4..18f7501290 100644 --- a/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherDslASTFactoryTest.java +++ b/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherDslASTFactoryTest.java @@ -104,7 +104,7 @@ class HandleNewMethods { @ParameterizedTest @ValueSource(strings = { "showAliases", "createLocalDatabaseAlias", "createRemoteDatabaseAlias", "alterLocalDatabaseAlias", "alterRemoteDatabaseAlias", "fixedPathQuantifier", - "useGraph", "setOwnPassword", "addDeprecatedIdentifierUnicodeNotification", + "useGraph", "setOwnPassword", "showAllPrivileges", "showRolePrivileges", "showUserPrivileges", "createDatabase", "createCompositeDatabase", "dropDatabase", "showDatabase", "startDatabase", "stopDatabase", "createUser", "dropUser", "alterUser", "renameUser", diff --git a/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherParserTest.java b/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherParserTest.java index 577f1b4496..ce48b602ef 100644 --- a/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherParserTest.java +++ b/neo4j-cypher-dsl-parser/src/test/java/org/neo4j/cypherdsl/parser/CypherParserTest.java @@ -838,4 +838,9 @@ void optionalSubquery() { CypherParser.parse("MATCH (n) OPTIONAL CALL() {MATCH (m)}")) .withMessage("Cannot render optional subquery clause"); } + + @Test + void unescapedThings() { + assertThat(CypherParser.parse("RETURN 1 AS v$_id").getCypher()).isEqualTo("RETURN 1 AS `v$_id`"); + } } diff --git a/neo4j-cypher-dsl-schema-name-support/src/main/java/org/neo4j/cypherdsl/support/schema_name/SchemaNames.java b/neo4j-cypher-dsl-schema-name-support/src/main/java/org/neo4j/cypherdsl/support/schema_name/SchemaNames.java index 903d62c161..f1c1b654d4 100644 --- a/neo4j-cypher-dsl-schema-name-support/src/main/java/org/neo4j/cypherdsl/support/schema_name/SchemaNames.java +++ b/neo4j-cypher-dsl-schema-name-support/src/main/java/org/neo4j/cypherdsl/support/schema_name/SchemaNames.java @@ -239,15 +239,16 @@ private static boolean isIdentifier(CharSequence name) { String id = name.toString(); int cp = id.codePointAt(0); - if (!Character.isJavaIdentifierStart(cp)) { + if (!Character.isJavaIdentifierStart(cp) || '$' == cp) { return false; } for (int i = Character.charCount(cp); i < id.length(); i += Character.charCount(cp)) { cp = id.codePointAt(i); - if (!Character.isJavaIdentifierPart(cp)) { + if (!Character.isJavaIdentifierPart(cp) || '$' == cp) { return false; } } + return true; }