From e25c440c99ef60f93fd30838f390c2cb0980a2f8 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 17 Feb 2015 14:02:40 +0000 Subject: [PATCH] Issue #2427773 by sun, daffie: SQLite REGEXP user function exists, but is wrongly implemented --- .../Core/Database/Driver/sqlite/Connection.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index bf2a9ac079b6..eaff2e154fd0 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -257,10 +257,16 @@ class Connection extends DatabaseConnection { /** * SQLite compatibility implementation for the REGEXP SQL operator. * - * The REGEXP operator is a special syntax for the regexp() user function. + * The REGEXP operator is natively known, but not implemented by default. + * + * @see http://www.sqlite.org/lang_expr.html#regexp */ - public static function sqlFunctionRegexp($string, $pattern) { - return preg_match('#' . str_replace('#', '\#', $pattern) . '#i', $string); + public static function sqlFunctionRegexp($pattern, $subject) { + // preg_quote() cannot be used here, since $pattern may contain reserved + // regular expression characters already (such as ^, $, etc). Therefore, + // use a rare character as PCRE delimiter. + $pattern = '#' . addcslashes($pattern, '#') . '#i'; + return preg_match($pattern, $subject); } /**