mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Switching FixtureTask to use var_export() instead of custom
escaping code. Fixes issues with quotes in text. Fixes #1922
This commit is contained in:
parent
f9ff4e1e68
commit
9daa969783
2 changed files with 31 additions and 13 deletions
|
@ -296,35 +296,30 @@ class FixtureTask extends BakeTask {
|
|||
$insert = substr($insert, 0, (int)$fieldInfo['length'] - 2);
|
||||
}
|
||||
}
|
||||
$insert = "'$insert'";
|
||||
break;
|
||||
case 'timestamp':
|
||||
$ts = time();
|
||||
$insert = "'$ts'";
|
||||
$insert = time();
|
||||
break;
|
||||
case 'datetime':
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
$insert = "'$ts'";
|
||||
$insert = date('Y-m-d H:i:s');
|
||||
break;
|
||||
case 'date':
|
||||
$ts = date('Y-m-d');
|
||||
$insert = "'$ts'";
|
||||
$insert = date('Y-m-d');
|
||||
break;
|
||||
case 'time':
|
||||
$ts = date('H:i:s');
|
||||
$insert = "'$ts'";
|
||||
$insert = date('H:i:s');
|
||||
break;
|
||||
case 'boolean':
|
||||
$insert = 1;
|
||||
break;
|
||||
case 'text':
|
||||
$insert = "'Lorem ipsum dolor sit amet, aliquet feugiat.";
|
||||
$insert = "Lorem ipsum dolor sit amet, aliquet feugiat.";
|
||||
$insert .= " Convallis morbi fringilla gravida,";
|
||||
$insert .= " phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin";
|
||||
$insert .= " venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla";
|
||||
$insert .= " vestibulum massa neque ut et, id hendrerit sit,";
|
||||
$insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus";
|
||||
$insert .= " duis vestibulum nunc mattis convallis.'";
|
||||
$insert .= " duis vestibulum nunc mattis convallis.";
|
||||
break;
|
||||
}
|
||||
$record[$field] = $insert;
|
||||
|
@ -346,7 +341,8 @@ class FixtureTask extends BakeTask {
|
|||
foreach ($records as $record) {
|
||||
$values = array();
|
||||
foreach ($record as $field => $value) {
|
||||
$values[] = "\t\t\t'$field' => $value";
|
||||
$val = var_export($value, true);
|
||||
$values[] = "\t\t\t'$field' => $val";
|
||||
}
|
||||
$out .= "\t\tarray(\n";
|
||||
$out .= implode(",\n", $values);
|
||||
|
@ -387,7 +383,7 @@ class FixtureTask extends BakeTask {
|
|||
foreach ($records as $record) {
|
||||
$row = array();
|
||||
foreach ($record[$modelObject->alias] as $field => $value) {
|
||||
$row[$field] = $db->value($value, $schema[$field]['type']);
|
||||
$row[$field] = $value;
|
||||
}
|
||||
$out[] = $row;
|
||||
}
|
||||
|
|
|
@ -167,6 +167,28 @@ class FixtureTaskTest extends CakeTestCase {
|
|||
$this->assertPattern('/Third Article/', $result, 'Missing import data %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that fixture data doesn't get overly escaped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testImportRecordsNoEscaping() {
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->updateAll(array('body' => "'Body \"value\"'"));
|
||||
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValueAt(0, 'in', 'WHERE 1=1 LIMIT 10');
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$result = $this->Task->bake('Article', false, array(
|
||||
'fromTable' => true,
|
||||
'schema' => 'Article',
|
||||
'records' => false
|
||||
));
|
||||
|
||||
$this->assertPattern("/'body' => 'Body \"value\"'/", $result, 'Data has escaping %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that execute passes runs bake depending with named model.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue