[DI] Fix possible incorrect php-code when dumped strings contains newlines
This commit is contained in:
parent
5e0bb5f973
commit
345f2fc60e
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue