[DI] Fix possible incorrect php-code when dumped strings contains newlines

This commit is contained in:
Artur Eshenbrener 2017-10-12 14:28:41 +03:00 committed by Nicolas Grekas
parent 5e0bb5f973
commit 345f2fc60e
3 changed files with 9 additions and 1 deletions

View File

@ -1574,6 +1574,13 @@ EOF;
return $dirname;
}
if (is_string($value) && false !== strpos($value, "\n")) {
$cleanParts = explode("\n", $value);
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
return implode('."\n".', $cleanParts);
}
return var_export($value, true);
}
}

View File

@ -55,6 +55,7 @@ class PhpDumperTest extends TestCase
'optimize concatenation with empty string' => 'string1%empty_value%string2',
'optimize concatenation from the start' => '%empty_value%start',
'optimize concatenation at the end' => 'end%empty_value%',
'new line' => "string with \nnew line",
));
$container = new ContainerBuilder();

View File

@ -56,7 +56,7 @@ class ProjectServiceContainer extends Container
*/
protected function getTestService()
{
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end'));
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end', 'new line' => 'string with '."\n".'new line'));
}
/**