From 2f616a9e0cdf1cba7ff657a232e7c5452af44091 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 24 Jun 2015 23:39:26 -0400 Subject: [PATCH] Fix greedy regex operators in Postgres driver. `*` is greedy in regex, and needs to be escaped so that SQL operators don't cause invalid SQL conditions to be created. Refs #6877 --- lib/Cake/Model/Datasource/Database/Postgres.php | 2 +- lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 21d82b191..033527ae0 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -98,7 +98,7 @@ class Postgres extends DboSource { * * @var array */ - protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', '~', '~*', '!~', '!~*', 'similar to'); + protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', '~', '~\*', '\!~', '\!~\*', 'similar to'); /** * Connects to the database using options in the given configuration array. diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index d51fd7c87..03a964de6 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -490,6 +490,10 @@ class PostgresTest extends CakeTestCase { $this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+'))); $this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+'))); $this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+'))); + $this->assertSame( + ' WHERE EXTRACT( \'YEAR\' FROM "User"."birthday" ) = 2015', + $this->Dbo->conditions(array('EXTRACT( \'YEAR\' FROM User.birthday )' => 2015)) + ); } /**