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
This commit is contained in:
mark_story 2015-06-24 23:39:26 -04:00
parent 0841c04351
commit 2f616a9e0c
2 changed files with 5 additions and 1 deletions

View file

@ -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.

View file

@ -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))
);
}
/**