diff --git a/src/Symfony/Component/Yaml/Escaper.php b/src/Symfony/Component/Yaml/Escaper.php index be846e50c7eb..2820778feac9 100644 --- a/src/Symfony/Component/Yaml/Escaper.php +++ b/src/Symfony/Component/Yaml/Escaper.php @@ -72,7 +72,15 @@ public static function escapeWithDoubleQuotes($value) */ public static function requiresSingleQuoting($value) { - return self::containsCharRequiresSingleQuoting($value) || self::isValueRequiresSingleQuoting($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)) { + 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')); } /** @@ -86,30 +94,4 @@ public static function escapeWithSingleQuotes($value) { return sprintf("'%s'", str_replace('\'', '\'\'', $value)); } - - /** - * Determines if a PHP value contains any single characters that would cause - * the value to require single quoting in YAML. - * - * @param string $value A PHP value - * @return bool True if the value would require single quotes. - */ - private static function containsCharRequiresSingleQuoting($value) - { - return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value); - } - - /** - * Determines if a PHP value is entirely composed of a value that would - * require single quoting in YAML. - * - * @param string $value A PHP value - * @return bool True if the value would require single quotes. - */ - private static function isValueRequiresSingleQuoting($value) - { - // Note that whilst 'y' and 'n' are not supported as valid Booleans, - // they are escaped here for interoperability. - return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off')); - } }