Skip to content

Commit

Permalink
bug #29571 [Yaml] ensures that the mb_internal_encoding is reset to i…
Browse files Browse the repository at this point in the history
…ts initial value (Jörn Lang)

This PR was merged into the 3.4 branch.

Discussion
----------

[Yaml] ensures that the mb_internal_encoding is reset to its initial value

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

When `Symfony\Component\Yaml\Inline::parse` sets the internal encoding to ASCII and the method does an early return or throws an exception, the internal encoding would not be reset.
This Patch ensures the reset of the encoding by moving it into a finally block.

Commits
-------

56ab129 [Yaml] ensures that the mb_internal_encoding is reset to its initial value
  • Loading branch information
xabbuh committed Dec 11, 2018
2 parents 9b7b862 + 56ab129 commit 4c8d04c
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/Symfony/Component/Yaml/Inline.php
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 4c8d04c

Please sign in to comment.