Issue #3415118 by ahmad.k, Lendude: Combine fields filter REGEXP causes PostgreSQL syntax error

merge-requests/6499/head^2
Alex Pott 2024-02-29 09:16:58 +00:00
parent eacd1fa3fd
commit b3c74ca14e
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 61 additions and 1 deletions

View File

@ -210,7 +210,8 @@ class Combine extends StringFilter {
protected function opRegex($expression) { protected function opRegex($expression) {
$placeholder = $this->placeholder(); $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) { protected function opEmpty($expression) {

View File

@ -98,6 +98,65 @@ class FilterCombineTest extends ViewsKernelTestBase {
$this->assertIdenticalResultset($view, $resultset, $this->columnMap); $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. * Tests the Combine field filter with the 'word' operator.
*/ */