From 56ab129b9600e854f58c33b2c4a422752056f2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Lang?= Date: Tue, 11 Dec 2018 14:45:34 +0100 Subject: [PATCH] [Yaml] ensures that the mb_internal_encoding is reset to its initial value --- src/Symfony/Component/Yaml/Inline.php | 52 ++++++++++++++------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 7c9d4e03b5fd..42b6cb10e7b1 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -110,35 +110,37 @@ public static function parse($value, $flags = 0, $references = array()) mb_internal_encoding('ASCII'); } - $i = 0; - $tag = self::parseTag($value, $i, $flags); - switch ($value[$i]) { - case '[': - $result = self::parseSequence($value, $flags, $i, $references); - ++$i; - break; - case '{': - $result = self::parseMapping($value, $flags, $i, $references); - ++$i; - break; - default: - $result = self::parseScalar($value, $flags, null, $i, null === $tag, $references); - } + try { + $i = 0; + $tag = self::parseTag($value, $i, $flags); + switch ($value[$i]) { + case '[': + $result = self::parseSequence($value, $flags, $i, $references); + ++$i; + break; + case '{': + $result = self::parseMapping($value, $flags, $i, $references); + ++$i; + break; + default: + $result = self::parseScalar($value, $flags, null, $i, null === $tag, $references); + } - if (null !== $tag) { - return new TaggedValue($tag, $result); - } + if (null !== $tag) { + return new TaggedValue($tag, $result); + } - // some comments are allowed at the end - if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { - throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename); - } + // some comments are allowed at the end + if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) { + throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename); + } - if (isset($mbEncoding)) { - mb_internal_encoding($mbEncoding); + return $result; + } finally { + if (isset($mbEncoding)) { + mb_internal_encoding($mbEncoding); + } } - - return $result; } /**