From b5e04c1d55443f90be49a42ee828f3f5869cef7e Mon Sep 17 00:00:00 2001
From: Oliver Hader <oliver@typo3.org>
Date: Fri, 8 Jul 2022 13:52:34 +0200
Subject: [PATCH] [TASK] Move escapeLikeWildcards to Connection

Escaping SQL `LIKE` wildcards is only provided via
`QueryBuilder::escapeLikeWildcards()`, but would be useful as
`Connection::escapeLikeWildcards()` as well (without having the
demand to create another `QueryBuilder` instance).

With this patch, both methods are available:
* `QueryBuilder::escapeLikeWildcards()`, and
* `Connection::escapeLikeWildcards()`

Resolves: #97878
Releases: main, 11.5, 10.4
Change-Id: Ia8968dee944300949c6bb2be5b15e2d02a589d25
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75061
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 typo3/sysext/core/Classes/Database/Connection.php    | 12 ++++++++++++
 .../core/Classes/Database/Query/QueryBuilder.php     |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/core/Classes/Database/Connection.php b/typo3/sysext/core/Classes/Database/Connection.php
index 553b7c99ed05..4accae5ffbca 100644
--- a/typo3/sysext/core/Classes/Database/Connection.php
+++ b/typo3/sysext/core/Classes/Database/Connection.php
@@ -187,6 +187,18 @@ class Connection extends \Doctrine\DBAL\Connection implements LoggerAwareInterfa
         return $this->quoteColumnValuePairs($input);
     }
 
+    /**
+     * Quotes like wildcards for given string value.
+     *
+     * @param string $value The value to be quoted.
+     *
+     * @return string The quoted value.
+     */
+    public function escapeLikeWildcards(string $value): string
+    {
+        return addcslashes($value, '_%');
+    }
+
     /**
      * Inserts a table row with specified data.
      *
diff --git a/typo3/sysext/core/Classes/Database/Query/QueryBuilder.php b/typo3/sysext/core/Classes/Database/Query/QueryBuilder.php
index ee5b2cbe97c9..e935bf2020e7 100644
--- a/typo3/sysext/core/Classes/Database/Query/QueryBuilder.php
+++ b/typo3/sysext/core/Classes/Database/Query/QueryBuilder.php
@@ -975,7 +975,7 @@ class QueryBuilder
      */
     public function escapeLikeWildcards(string $value): string
     {
-        return addcslashes($value, '_%');
+        return $this->connection->escapeLikeWildcards($value);
     }
 
     /**
-- 
GitLab