diff options
Diffstat (limited to 'vendor/symfony/var-exporter/Internal/Exporter.php')
| -rw-r--r-- | vendor/symfony/var-exporter/Internal/Exporter.php | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/vendor/symfony/var-exporter/Internal/Exporter.php b/vendor/symfony/var-exporter/Internal/Exporter.php index c0b7fa17f4..06d747e138 100644 --- a/vendor/symfony/var-exporter/Internal/Exporter.php +++ b/vendor/symfony/var-exporter/Internal/Exporter.php @@ -212,27 +212,28 @@ class Exporter $subIndent = $indent.' '; if (\is_string($value)) { - $code = var_export($value, true); + $code = sprintf("'%s'", addcslashes($value, "'\\")); - if (false !== strpos($value, "\n") || false !== strpos($value, "\r")) { - $code = strtr($code, [ - "\r\n" => "'.\"\\r\\n\"\n".$subIndent.".'", - "\r" => "'.\"\\r\"\n".$subIndent.".'", - "\n" => "'.\"\\n\"\n".$subIndent.".'", - ]); - } + $code = preg_replace_callback('/([\0\r\n]++)(.)/', function ($m) use ($subIndent) { + $m[1] = sprintf('\'."%s".\'', str_replace( + ["\0", "\r", "\n", '\n\\'], + ['\0', '\r', '\n', '\n"'."\n".$subIndent.'."\\'], + $m[1] + )); - if (false !== strpos($value, "\0")) { - $code = str_replace('\' . "\0" . \'', '\'."\0".\'', $code); - $code = str_replace('".\'\'."', '', $code); - } + if ("'" === $m[2]) { + return substr($m[1], 0, -2); + } - if (false !== strpos($code, "''.")) { - $code = str_replace("''.", '', $code); - } + if ('n".\'' === substr($m[1], -4)) { + return substr_replace($m[1], "\n".$subIndent.".'".$m[2], -2); + } + + return $m[1].$m[2]; + }, $code, -1, $count); - if (".''" === substr($code, -3)) { - $code = rtrim(substr($code, 0, -3)); + if ($count && 0 === strpos($code, "''.")) { + $code = substr($code, 3); } return $code; |
