Skip to content

Commit

Permalink
[Yaml] fixed UTF-8 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 27, 2010
1 parent a54fcaa commit d8efe7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Components/Yaml/Inline.php
Expand Up @@ -193,7 +193,7 @@ static public function parseScalar($scalar, $delimiters = null, $stringDelimiter
*/
static protected function parseQuotedScalar($scalar, &$i)
{
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/A', substr($scalar, $i), $match)) {
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
throw new ParserException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
}

Expand Down
20 changes: 10 additions & 10 deletions src/Symfony/Components/Yaml/Parser.php
Expand Up @@ -52,7 +52,7 @@ public function parse($value)

if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
mb_internal_encoding('UTF-8');
}

$data = array();
Expand All @@ -67,8 +67,8 @@ public function parse($value)
}

$isRef = $isInPlace = $isProcessed = false;
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#', $this->currentLine, $values)) {
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#', $values['value'], $matches)) {
if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values)) {
if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {
$isRef = $matches['ref'];
$values['value'] = $matches['value'];
}
Expand All @@ -82,7 +82,7 @@ public function parse($value)
} else {
if (isset($values['leadspaces'])
&& ' ' == $values['leadspaces']
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#', $values['value'], $matches)
&& preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches)
) {
// this is a compact notation element, add to next block and parse
$c = $this->getRealCurrentLineNb();
Expand All @@ -99,7 +99,7 @@ public function parse($value)
$data[] = $this->parseValue($values['value']);
}
}
} else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#', $this->currentLine, $values)) {
} else if (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values)) {
$key = Inline::parseScalar($values['key']);

if ('<<' === $key) {
Expand Down Expand Up @@ -137,7 +137,7 @@ public function parse($value)

$isProcessed = $merged;
}
} else if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#', $values['value'], $matches)) {
} else if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) {
$isRef = $matches['ref'];
$values['value'] = $matches['value'];
}
Expand Down Expand Up @@ -375,7 +375,7 @@ protected function parseFoldedScalar($separator, $indicator = '', $indentation =
return '';
}

if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#', $this->currentLine, $matches)) {
if (!preg_match('#^(?P<indent>'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P<text>.*)$#u', $this->currentLine, $matches)) {
$this->moveToPreviousLine();

return '';
Expand All @@ -388,7 +388,7 @@ protected function parseFoldedScalar($separator, $indicator = '', $indentation =
while ($this->currentLineNb + 1 < count($this->lines)) {
$this->moveToNextLine();

if (preg_match('#^(?P<indent> {'.strlen($textIndent).',})(?P<text>.+)$#', $this->currentLine, $matches)) {
if (preg_match('#^(?P<indent> {'.strlen($textIndent).',})(?P<text>.+)$#u', $this->currentLine, $matches)) {
if (' ' == $separator && $previousIndent != $matches['indent']) {
$text = substr($text, 0, -1)."\n";
}
Expand Down Expand Up @@ -500,11 +500,11 @@ protected function cleanup($value)

// strip YAML header
$count = 0;
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#s', '', $value, -1, $count);
$value = preg_replace('#^\%YAML[: ][\d\.]+.*\n#su', '', $value, -1, $count);
$this->offset += $count;

// remove leading comments and/or ---
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\n))*#s', '', $value, -1, $count);
$trimmedValue = preg_replace('#^((\#.*?\n)|(\-\-\-.*?\n))*#su', '', $value, -1, $count);
if ($count == 1) {
// items have been removed, update the offset
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
Expand Down

0 comments on commit d8efe7e

Please sign in to comment.