This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 4_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/4_1_X by this push:
     new c00e82dd3a Fix improper backslash escaping in Neo4j
c00e82dd3a is described below

commit c00e82dd3a0a8673de4dd0b3ad88e66e9dfd63c1
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Mon Nov 23 13:04:23 2026 +0100

    Fix improper backslash escaping in Neo4j
---
 .../persistence/neo4j/dao/repo/AnyRepoExt.java     |  2 +-
 .../persistence/neo4j/dao/repo/AnyRepoExtTest.java | 42 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git 
a/core/persistence-neo4j/src/main/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExt.java
 
b/core/persistence-neo4j/src/main/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExt.java
index 2837136174..6cd46d4a45 100644
--- 
a/core/persistence-neo4j/src/main/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExt.java
+++ 
b/core/persistence-neo4j/src/main/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExt.java
@@ -40,7 +40,7 @@ public interface AnyRepoExt<A extends Any> {
     String REGEX_CHARS = "{}[]()?+*.\"'";
 
     static String escapeForLikeRegex(final String input) {
-        String output = input;
+        String output = input.replace("\\", "\\\\");
         for (char toEscape : REGEX_CHARS.toCharArray()) {
             output = output.replace(String.valueOf(toEscape), "\\" + toEscape);
         }
diff --git 
a/core/persistence-neo4j/src/test/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExtTest.java
 
b/core/persistence-neo4j/src/test/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExtTest.java
new file mode 100644
index 0000000000..e2a7e81137
--- /dev/null
+++ 
b/core/persistence-neo4j/src/test/java/org/apache/syncope/core/persistence/neo4j/dao/repo/AnyRepoExtTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
+ *
+ *   http://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.
+ */
+package org.apache.syncope.core.persistence.neo4j.dao.repo;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class AnyRepoExtTest {
+
+    @Test
+    public void escapeForLikeRegexShouldEscapeBackslash() {
+        // Any plain-attribute search value ending with a backslash must have 
the
+        // backslash itself escaped before the regular expression 
metacharacters are
+        // escaped. Otherwise the generated Cypher string literal contains an 
escaped
+        // closing quote and remains unterminated, corrupting the query 
structure.
+        assertEquals("foo\\\\", AnyRepoExt.escapeForLikeRegex("foo\\"));
+    }
+
+    @Test
+    public void 
escapeForLikeRegexShouldEscapeRegularExpressionMetacharacters() {
+        assertEquals("foo", AnyRepoExt.escapeForLikeRegex("foo"));
+        assertEquals("f\\.oo", AnyRepoExt.escapeForLikeRegex("f.oo"));
+        assertEquals("f\\*o\\*o", AnyRepoExt.escapeForLikeRegex("f*o*o"));
+    }
+}

Reply via email to