mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing DboSource not quoting table/field names with - in them. Tests expanded . Fixes #323
This commit is contained in:
parent
416abed211
commit
7075aa5e86
2 changed files with 8 additions and 7 deletions
|
@ -472,9 +472,6 @@ class DboSource extends DataSource {
|
||||||
if (is_object($data) && isset($data->type)) {
|
if (is_object($data) && isset($data->type)) {
|
||||||
return $data->value;
|
return $data->value;
|
||||||
}
|
}
|
||||||
if ($data == '*') {
|
|
||||||
return '*';
|
|
||||||
}
|
|
||||||
if ($data === '*') {
|
if ($data === '*') {
|
||||||
return '*';
|
return '*';
|
||||||
}
|
}
|
||||||
|
@ -492,20 +489,20 @@ class DboSource extends DataSource {
|
||||||
return $this->methodCache[__FUNCTION__][$cacheKey];
|
return $this->methodCache[__FUNCTION__][$cacheKey];
|
||||||
}
|
}
|
||||||
$data = trim($data);
|
$data = trim($data);
|
||||||
if (preg_match('/^\w+(\.\w+)*$/', $data)) { // string, string.string
|
if (preg_match('/^[\w-]+(\.[\w-]+)*$/', $data)) { // string, string.string
|
||||||
if (strpos($data, '.') === false) { // string
|
if (strpos($data, '.') === false) { // string
|
||||||
return $this->startQuote . $data . $this->endQuote;
|
return $this->startQuote . $data . $this->endQuote;
|
||||||
}
|
}
|
||||||
$items = explode('.', $data);
|
$items = explode('.', $data);
|
||||||
return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
|
return $this->startQuote . implode($this->endQuote . '.' . $this->startQuote, $items) . $this->endQuote;
|
||||||
}
|
}
|
||||||
if (preg_match('/^\w+\.\*$/', $data)) { // string.*
|
if (preg_match('/^[\w-]+\.\*$/', $data)) { // string.*
|
||||||
return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
|
return $this->startQuote . str_replace('.*', $this->endQuote . '.*', $data);
|
||||||
}
|
}
|
||||||
if (preg_match('/^(\w+)\((.*)\)$/', $data, $matches)) { // Functions
|
if (preg_match('/^([\w-]+)\((.*)\)$/', $data, $matches)) { // Functions
|
||||||
return $matches[1] . '(' . $this->name($matches[2]) . ')';
|
return $matches[1] . '(' . $this->name($matches[2]) . ')';
|
||||||
}
|
}
|
||||||
if (preg_match('/^(\w+(\.\w+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*(\w+)$/', $data, $matches)) {
|
if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/', $data, $matches)) {
|
||||||
return preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
|
return preg_replace('/\s{2,}/', ' ', $this->name($matches[1]) . ' ' . $this->alias . ' ' . $this->name($matches[3]));
|
||||||
}
|
}
|
||||||
return $this->methodCache[__FUNCTION__][$cacheKey] = $data;
|
return $this->methodCache[__FUNCTION__][$cacheKey] = $data;
|
||||||
|
|
|
@ -4037,6 +4037,10 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$result = $this->testDb->name('name-with-minus');
|
$result = $this->testDb->name('name-with-minus');
|
||||||
$expected = '`name-with-minus`';
|
$expected = '`name-with-minus`';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = $this->testDb->name(array('my-name', 'Foo-Model.*'));
|
||||||
|
$expected = array('`my-name`', '`Foo-Model`.*');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue