Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2ed37c

Browse files
committed
minor #14107 Add parsing of hexadecimal strings for PHP 7 (stof)
This PR was merged into the 2.3 branch. Discussion ---------- Add parsing of hexadecimal strings for PHP 7 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14086 | License | MIT | Doc PR | n/a PHP 7 does not handle the hexadecimal notation in is_numeric checks anymore, so the detection needs to be implemented explicitly. With this change, we should have a passing testsuite on PHP 7 Commits ------- e848040 Add parsing of hexadecimal strings for PHP 7
2 parents 4f25914 + e848040 commit e2ed37c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Config/Util/XmlUtils.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ public static function phpize($value)
200200
return false;
201201
case is_numeric($value):
202202
return '0x' === $value[0].$value[1] ? hexdec($value) : (float) $value;
203+
case preg_match('/^0x[0-9a-f]++$/i', $value):
204+
return hexdec($value);
203205
case preg_match('/^(-|\+)?[0-9]+(\.[0-9]+)?$/', $value):
204206
return (float) $value;
205207
default:

src/Symfony/Component/Yaml/Inline.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp
137137
case Escaper::requiresDoubleQuoting($value):
138138
return Escaper::escapeWithDoubleQuotes($value);
139139
case Escaper::requiresSingleQuoting($value):
140+
case preg_match(self::getHexRegex(), $value):
140141
case preg_match(self::getTimestampRegex(), $value):
141142
return Escaper::escapeWithSingleQuotes($value);
142143
default:
@@ -454,6 +455,7 @@ private static function evaluateScalar($scalar, $references = array())
454455

455456
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw);
456457
case is_numeric($scalar):
458+
case preg_match(self::getHexRegex(), $scalar):
457459
return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar;
458460
case '.inf' === $scalarLower:
459461
case '.nan' === $scalarLower:
@@ -494,4 +496,14 @@ private static function getTimestampRegex()
494496
$~x
495497
EOF;
496498
}
499+
500+
/**
501+
* Gets a regex that matches a YAML number in hexadecimal notation.
502+
*
503+
* @return string
504+
*/
505+
private static function getHexRegex()
506+
{
507+
return '~^0x[0-9a-f]++$~i';
508+
}
497509
}

0 commit comments

Comments
 (0)