diff --git a/src/Symfony/Component/Yaml/Escaper.php b/src/Symfony/Component/Yaml/Escaper.php index 2820778feac94..f4987652aa5d6 100644 --- a/src/Symfony/Component/Yaml/Escaper.php +++ b/src/Symfony/Component/Yaml/Escaper.php @@ -72,15 +72,15 @@ public static function escapeWithDoubleQuotes($value) */ public static function requiresSingleQuoting($value) { - // Determines if the PHP value contains any single characters that would - // cause it to require single quoting in YAML. - if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) { + // Determines if a PHP value is entirely composed of a value that would + // require single quoting in YAML. + if (in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) { return true; } - // Determines if a PHP value is entirely composed of a value that would - // require single quoting in YAML. - return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off')); + // Determines if the PHP value contains any single characters that would + // cause it to require single quoting in YAML. + return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value); } /** diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 1bdcf87623408..3aa248b2f4a33 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -132,13 +132,13 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp } return $repr; + case '' == $value: + return "''"; case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): case preg_match(self::getTimestampRegex(), $value): return Escaper::escapeWithSingleQuotes($value); - case '' == $value: - return "''"; default: return $value; }