Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue created in [e8b5d81]

Query conditions with `-` and no surrounding spaces were quoted
incorrectly.

Fixes #3178
  • Loading branch information...
commit 3cb501f1c50635d1cd536651bd12ff7add237cc0 1 parent 583bb37
@markstory markstory authored
View
2  lib/Cake/Model/Datasource/DboSource.php
@@ -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
);
View
16 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
@@ -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);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.