Browse files

Fix quoting of field names containing `-`.

Fixes #3165
  • Loading branch information...
1 parent 3e17c7a commit e8b5d81fd728725279dd60005d07319bdaa5f4a6 @markstory markstory committed Aug 31, 2012
View
8 lib/Cake/Model/Datasource/DboSource.php
@@ -2315,7 +2315,6 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
}
$fields = array_values($fields);
}
-
if (!$quote) {
if (!empty($virtual)) {
$fields = array_merge($fields, $this->_constructVirtualFields($model, $alias, $virtual));
@@ -2633,8 +2632,11 @@ protected function _quoteFields($conditions) {
$end = preg_quote($this->endQuote);
}
$conditions = str_replace(array($start, $end), '', $conditions);
- $conditions = preg_replace_callback('/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_' . $start . $end . ']*\\.[a-z0-9_' . $start . $end . ']*)/i', array(&$this, '_quoteMatchedField'), $conditions);
-
+ $conditions = preg_replace_callback(
+ '/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9\\-_' . $start . $end . ']*\\.[a-z0-9_\\-' . $start . $end . ']*)/i',
+ array(&$this, '_quoteMatchedField'),
+ $conditions
+ );
if ($conditions !== null) {
return $conditions;
}
View
6 lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php
@@ -403,8 +403,12 @@ public function testLocaleMultiple() {
)
)
);
-
$this->assertEquals($expected, $result);
+
+ $TestModel = new TranslatedItem();
+ $TestModel->locale = array('pt-br');
+ $result = $TestModel->find('all');
+ $this->assertCount(3, $result, '3 records should have been found, no SQL error.');
}
/**
View
3 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
@@ -2017,6 +2017,9 @@ 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);
+
+ $result = $this->Dbo->conditions('I18n__title_pt-br.content = "test"');
+ $this->assertEquals(' WHERE `I18n__title_pt-br`.`content` = "test"', $result);
}
/**
View
4 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -585,6 +585,10 @@ public function testName() {
$expected = 'Function(`Something`.`foo`) AS `x`';
$this->assertEquals($expected, $result);
+ $result = $this->testDb->name('I18n__title__pt-br.locale');
+ $expected = '`I18n__title__pt-br`.`locale`';
+ $this->assertEquals($expected, $result);
+
$result = $this->testDb->name('name-with-minus');
$expected = '`name-with-minus`';
$this->assertEquals($expected, $result);

0 comments on commit e8b5d81

Please sign in to comment.