From e848040e9e9444e9864776ababb2a597aecb7d0d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 30 Mar 2015 09:37:12 +0200 Subject: [PATCH] Add parsing of hexadecimal strings for PHP 7 PHP 7 does not handle the hexadecimal notation in is_numeric checks anymore, so the detection needs to be implemented explicitly. --- src/Symfony/Component/Config/Util/XmlUtils.php | 2 ++ src/Symfony/Component/Yaml/Inline.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index 34ad20e459f72..56613bbb42633 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -200,6 +200,8 @@ public static function phpize($value) return false; case is_numeric($value): return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value; + case preg_match('/^0x[0-9a-f]++$/i', $value): + return hexdec($value); case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value): return (float) $value; default: diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 6564ad4422134..6d21a48f41142 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -137,6 +137,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp case Escaper::requiresDoubleQuoting($value): return Escaper::escapeWithDoubleQuotes($value); case Escaper::requiresSingleQuoting($value): + case preg_match(self::getHexRegex(), $value): case preg_match(self::getTimestampRegex(), $value): return Escaper::escapeWithSingleQuotes($value); default: @@ -454,6 +455,7 @@ private static function evaluateScalar($scalar, $references = array()) return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw); case is_numeric($scalar): + case preg_match(self::getHexRegex(), $scalar): return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar; case '.inf' === $scalarLower: case '.nan' === $scalarLower: @@ -494,4 +496,14 @@ private static function getTimestampRegex() $~x EOF; } + + /** + * Gets a regex that matches a YAML number in hexadecimal notation. + * + * @return string + */ + private static function getHexRegex() + { + return '~^0x[0-9a-f]++$~i'; + } }