8000 Inline private 'is quoting required' methods in Escaper · symfony/symfony@8fa056b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fa056b

Browse files
author
pthompson
committed
Inline private 'is quoting required' methods in Escaper
1 parent afe827a commit 8fa056b

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

src/Symfony/Component/Yaml/Escaper.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ public static function escapeWithDoubleQuotes($value)
7272
*/
7373
public static function requiresSingleQuoting($value)
7474
{
75-
return self::containsCharRequiresSingleQuoting($value) || self::isValueRequiresSingleQuoting($value);
75+
// Determines if the PHP value contains any single characters that would
76+
// cause it to require single quoting in YAML.
77+
if (preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value)) {
78+
return true;
79+
}
80+
81+
// Determines if a PHP value is entirely composed of a value that would
82+
// require single quoting in YAML.
83+
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
7684
}
7785

7886
/**
@@ -86,30 +94,4 @@ public static function escapeWithSingleQuotes($value)
8694
{
8795
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
8896
}
89-
90-
/**
91-
* Determines if a PHP value contains any single characters that would cause
92-
* the value to require single quoting in YAML.
93-
*
94-
* @param string $value A PHP value
95-
* @return bool True if the value would require single quotes.
96-
*/
97-
private static function containsCharRequiresSingleQuoting($value)
98-
{
99-
return preg_match('/[ \s \' " \: \{ \} \[ \] , & \* \# \?] | \A[ \- ? | < > = ! % @ ` ]/x', $value);
100-
}
101-
102-
/**
103-
* Determines if a PHP value is entirely composed of a value that would
104-
* require single quoting in YAML.
105-
*
106-
* @param string $value A PHP value
107-
* @return bool True if the value would require single quotes.
108-
*/
109-
private static function isValueRequiresSingleQuoting($value)
110-
{
111-
// Note that whilst 'y' and 'n' are not supported as valid Booleans,
112-
// they are escaped here for interoperability.
113-
return in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'));
114-
}
11597
}

0 commit comments

Comments
 (0)
0