From b3c74ca14ef50d4b2b6dceba014c3649fb337008 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 29 Feb 2024 09:16:58 +0000
Subject: [PATCH] Issue #3415118 by ahmad.k, Lendude: Combine fields filter
 REGEXP causes PostgreSQL syntax error

---
 .../views/src/Plugin/views/filter/Combine.php |  3 +-
 .../src/Kernel/Handler/FilterCombineTest.php  | 59 +++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/core/modules/views/src/Plugin/views/filter/Combine.php b/core/modules/views/src/Plugin/views/filter/Combine.php
index bffce7a8962c..439888273817 100644
--- a/core/modules/views/src/Plugin/views/filter/Combine.php
+++ b/core/modules/views/src/Plugin/views/filter/Combine.php
@@ -210,7 +210,8 @@ protected function opNotLike($expression) {
 
   protected function opRegex($expression) {
     $placeholder = $this->placeholder();
-    $this->query->addWhereExpression($this->options['group'], "$expression REGEXP $placeholder", [$placeholder => $this->value]);
+    $operator = $this->getConditionOperator('REGEXP');
+    $this->query->addWhereExpression($this->options['group'], "$expression $operator $placeholder", [$placeholder => $this->value]);
   }
 
   protected function opEmpty($expression) {
diff --git a/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php b/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php
index ea079c488aa2..57a6d6d71d8a 100644
--- a/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php
+++ b/core/modules/views/tests/src/Kernel/Handler/FilterCombineTest.php
@@ -98,6 +98,65 @@ public function testFilterCombineContains() {
     $this->assertIdenticalResultset($view, $resultset, $this->columnMap);
   }
 
+  /**
+   * Tests the Combine field filter with the 'regular_expression' operator.
+   */
+  public function testFilterCombineRegEx() {
+    $view = Views::getView('test_view');
+    $view->setDisplay();
+
+    $fields = $view->displayHandlers->get('default')->getOption('fields');
+    $view->displayHandlers->get('default')->overrideOption('fields', $fields + [
+      'job' => [
+        'id' => 'job',
+        'table' => 'views_test_data',
+        'field' => 'job',
+        'relationship' => 'none',
+      ],
+    ]);
+
+    // Change the filtering.
+    $view->displayHandlers->get('default')->overrideOption('filters', [
+      'age' => [
+        'id' => 'combine',
+        'table' => 'views',
+        'field' => 'combine',
+        'relationship' => 'none',
+        'operator' => 'regular_expression',
+        'fields' => [
+          'name',
+          'job',
+        ],
+        'value' => '(ing|write)',
+      ],
+    ]);
+
+    $this->executeView($view);
+    $resultset = [
+      [
+        'name' => 'John',
+        'job' => 'Singer',
+      ],
+      [
+        'name' => 'George',
+        'job' => 'Singer',
+      ],
+      [
+        'name' => 'Ringo',
+        'job' => 'Drummer',
+      ],
+      [
+        'name' => 'Paul',
+        'job' => 'Songwriter',
+      ],
+      [
+        'name' => 'Ginger',
+        'job' => NULL,
+      ],
+    ];
+    $this->assertIdenticalResultset($view, $resultset, $this->columnMap);
+  }
+
   /**
    * Tests the Combine field filter with the 'word' operator.
    */
-- 
GitLab