Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switching FixtureTask to use var_export() instead of custom

escaping code.
Fixes issues with quotes in text.
Fixes #1922
  • Loading branch information...
commit 9daa969783e26d2d478d20c193a70384a303454e 1 parent f9ff4e1
@markstory markstory authored
View
22 cake/console/libs/tasks/fixture.php
@@ -296,35 +296,30 @@ function _generateRecords($tableInfo, $recordCount = 1) {
$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 @@ function _makeRecordString($records) {
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 @@ function _getRecordsFromTable($modelName, $useTable = null) {
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;
}
View
22 cake/tests/cases/console/libs/tasks/fixture.test.php
@@ -168,6 +168,28 @@ function testImportRecordsFromDatabaseWithConditions() {
}
/**
+ * 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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.