Skip to content

Commit

Permalink
Fix greedy regex operators in Postgres driver.
Browse files Browse the repository at this point in the history
`*` is greedy in regex, and needs to be escaped so that SQL operators
don't cause invalid SQL conditions to be created.

Refs #6877
  • Loading branch information
markstory committed Jun 25, 2015
1 parent 0841c04 commit 2f616a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
Expand Up @@ -490,6 +490,10 @@ public function testRegexpOperatorConditionsParsing() {
$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))
);
}

/**
Expand Down

0 comments on commit 2f616a9

Please sign in to comment.