You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2024/01/04 09:55:31 UTC

(syncope) branch 3_0_X updated: [SYNCOPE-1800] Correct escape for single quote added also when regex is used (#593)

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

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


The following commit(s) were added to refs/heads/3_0_X by this push:
     new e7580420f4 [SYNCOPE-1800] Correct escape for single quote added also when regex is used (#593)
e7580420f4 is described below

commit e7580420f49457627829c3f0dc038d9d4a8da053
Author: Francesco Chicchiriccò <il...@users.noreply.github.com>
AuthorDate: Thu Jan 4 10:55:26 2024 +0100

    [SYNCOPE-1800] Correct escape for single quote added also when regex is used (#593)
---
 .../persistence/jpa/dao/PGJPAJSONAnySearchDAO.java |  2 +-
 .../org/apache/syncope/fit/core/SearchITCase.java  | 25 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
index b8c7f3d603..2a829bc461 100644
--- a/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
+++ b/core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
@@ -73,7 +73,7 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
         for (char toEscape : POSTGRESQL_REGEX_CHARS.toCharArray()) {
             output = output.replace(String.valueOf(toEscape), "\\" + toEscape);
         }
-        return output;
+        return output.replace("'", "''");
     }
 
     protected static String escapeIfString(final String value, final boolean isStr) {
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
index 7737210733..9c228393b0 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java
@@ -979,4 +979,29 @@ public class SearchITCase extends AbstractITCase {
                 allMatch(u -> "verdi@syncope.org".equals(u.getPlainAttr("email").orElseThrow().getValues().get(0))));
         assertTrue(users.getResult().stream().noneMatch(u -> user.getKey().equals(u.getKey())));
     }
+
+    @Test
+    public void issueSYNCOPE1800() {
+        // 1. create user
+        UserCR userCR = UserITCase.getUniqueSample("syncope800@syncope.apache.org");
+        Attr surname = userCR.getPlainAttr("surname").orElseThrow();
+        surname.getValues().clear();
+        surname.getValues().add("D'Amico");
+        UserTO user = createUser(userCR).getEntity();
+        assertEquals("D'Amico", user.getPlainAttr("surname").orElseThrow().getValues().get(0));
+
+        // 2. search for user
+        if (IS_EXT_SEARCH_ENABLED) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException ex) {
+                // ignore
+            }
+        }
+
+        PagedResult<UserTO> users = USER_SERVICE.search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+                fiql("surname=~D'*").build());
+        assertEquals(1, users.getResult().size());
+        assertEquals(user.getKey(), users.getResult().get(0).getKey());
+    }
 }