Skip to content

Commit fac7c48

Browse files
author
Jörn Lang
committed
[Yaml] ensures that the mb_internal_encoding is reset to its initial value
1 parent 291e13d commit fac7c48

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

Inline.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,37 @@ public static function parse($value, $flags = 0, $references = array())
110110
mb_internal_encoding('ASCII');
111111
}
112112

113-
$i = 0;
114-
$tag = self::parseTag($value, $i, $flags);
115-
switch ($value[$i]) {
116-
case '[':
117-
$result = self::parseSequence($value, $flags, $i, $references);
118-
++$i;
119-
break;
120-
case '{':
121-
$result = self::parseMapping($value, $flags, $i, $references);
122-
++$i;
123-
break;
124-
default:
125-
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
126-
}
113+
try {
114+
$i = 0;
115+
$tag = self::parseTag($value, $i, $flags);
116+
switch ($value[$i]) {
117+
case '[':
118+
$result = self::parseSequence($value, $flags, $i, $references);
119+
++$i;
120+
break;
121+
case '{':
122+
$result = self::parseMapping($value, $flags, $i, $references);
123+
++$i;
124+
break;
125+
default:
126+
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
127+
}
127128

128-
if (null !== $tag) {
129-
return new TaggedValue($tag, $result);
130-
}
129+
if (null !== $tag) {
130+
return new TaggedValue($tag, $result);
131+
}
131132

132-
// some comments are allowed at the end
133-
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
134-
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
135-
}
133+
// some comments are allowed at the end
134+
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
135+
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
136+
}
136137

137-
if (isset($mbEncoding)) {
138-
mb_internal_encoding($mbEncoding);
138+
return $result;
139+
} finally {
140+
if (isset($mbEncoding)) {
141+
mb_internal_encoding($mbEncoding);
142+
}
139143
}
140-
141-
return $result;
142144
}
143145

144146
/**

0 commit comments

Comments
 (0)