From f387675d7f5fc4231f7554baa70681f222f73563 Mon Sep 17 00:00:00 2001 From: Michel Roca Date: Fri, 3 Nov 2023 15:33:45 +0100 Subject: [PATCH] [Yaml] Fix uid binary parsing --- Inline.php | 2 +- Tests/InlineTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Inline.php b/Inline.php index 5b5f9613..712add90 100644 --- a/Inline.php +++ b/Inline.php @@ -531,7 +531,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a if ('<<' === $key) { $output += $value; } elseif ($allowOverwrite || !isset($output[$key])) { - if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) { + if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && !self::isBinaryString($value) && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) { $references[$matches['ref']] = $matches['value']; $value = $matches['value']; } diff --git a/Tests/InlineTest.php b/Tests/InlineTest.php index 07d4e04d..d6e02fad 100644 --- a/Tests/InlineTest.php +++ b/Tests/InlineTest.php @@ -368,6 +368,9 @@ public static function getTestsForParse() ['[foo, bar: { foo: bar }]', ['foo', '1' => ['bar' => ['foo' => 'bar']]]], ['[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', ['foo', '@foo.baz', ['%foo%' => 'foo is %foo%', 'bar' => '%foo%'], true, '@service_container']], + + // Binary string not utf8-compliant but starting with and utf8-equivalent "&" character + ['{ uid: !!binary Ju0Yh+uqSXOagJZFTlUt8g== }', ['uid' => hex2bin('26ed1887ebaa49739a8096454e552df2')]], ]; }