Skip to content

Commit

Permalink
Fix issue created in [e8b5d81]
Browse files Browse the repository at this point in the history
Query conditions with `-` and no surrounding spaces were quoted
incorrectly.

Fixes #3178
  • Loading branch information
markstory committed Sep 3, 2012
1 parent 583bb37 commit 3cb501f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -2633,7 +2633,7 @@ protected function _quoteFields($conditions) {
}
$conditions = str_replace(array($start, $end), '', $conditions);
$conditions = preg_replace_callback(
'/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9\\-_' . $start . $end . ']*\\.[a-z0-9_\\-' . $start . $end . ']*)/i',
'/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*)/i',
array(&$this, '_quoteMatchedField'),
$conditions
);
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -2017,9 +2017,25 @@ public function testQuotesInStringConditions() {
$result = $this->Dbo->conditions('Member.email = "mariano@cricava.com" AND Member.user LIKE "mariano.iglesias%"');
$expected = ' WHERE `Member`.`email` = "mariano@cricava.com" AND `Member`.`user` LIKE "mariano.iglesias%"';
$this->assertEquals($expected, $result);
}

/**
* test that - in conditions and field names works
*
* @return void
*/
public function testHypenInStringConditionsAndFieldNames() {
$result = $this->Dbo->conditions('I18n__title_pt-br.content = "test"');
$this->assertEquals(' WHERE `I18n__title_pt-br`.`content` = "test"', $result);

$result = $this->Dbo->conditions('Model.field=NOW()-3600');
$this->assertEquals(' WHERE `Model`.`field`=NOW()-3600', $result);

$result = $this->Dbo->conditions('NOW() - Model.created < 7200');
$this->assertEquals(' WHERE NOW() - `Model`.`created` < 7200', $result);

$result = $this->Dbo->conditions('NOW()-Model.created < 7200');
$this->assertEquals(' WHERE NOW()-`Model`.`created` < 7200', $result);
}

/**
Expand Down

0 comments on commit 3cb501f

Please sign in to comment.