Fixing order condition quoting to allow fields with - in them. Fixes #1599

This commit is contained in:
mark_story 2011-03-24 22:28:11 -04:00
parent b8e560b8b4
commit 532555b94b
2 changed files with 5 additions and 1 deletions

View file

@ -2439,7 +2439,7 @@ class DboSource extends DataSource {
} }
if (strpos($key, '.')) { if (strpos($key, '.')) {
$key = preg_replace_callback('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', array(&$this, '__quoteMatchedField'), $key); $key = preg_replace_callback('/([a-zA-Z0-9_-]{1,})\\.([a-zA-Z0-9_-]{1,})/', array(&$this, '__quoteMatchedField'), $key);
} }
if (!preg_match('/\s/', $key) && !strpos($key, '.')) { if (!preg_match('/\s/', $key) && !strpos($key, '.')) {
$key = $this->name($key); $key = $this->name($key);

View file

@ -3512,6 +3512,10 @@ class DboSourceTest extends CakeTestCase {
$result = $this->testDb->order(array('Property.sale_price IS NULL')); $result = $this->testDb->order(array('Property.sale_price IS NULL'));
$expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC'; $expected = ' ORDER BY `Property`.`sale_price` IS NULL ASC';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$result = $this->testDb->order(array('Export.column-name' => 'ASC'));
$expected = ' ORDER BY `Export`.`column-name` ASC';
$this->assertEqual($result, $expected, 'Columns with -s are not working with order()');
} }
/** /**