From d8efe7edb729e9da0629e5a80c7e6ac52e4393de Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 27 Jun 2010 13:59:29 +0200 Subject: [PATCH] [Yaml] fixed UTF-8 bug --- src/Symfony/Components/Yaml/Inline.php | 2 +- src/Symfony/Components/Yaml/Parser.php | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Components/Yaml/Inline.php b/src/Symfony/Components/Yaml/Inline.php index 978af3783c..b5796055f0 100644 --- a/src/Symfony/Components/Yaml/Inline.php +++ b/src/Symfony/Components/Yaml/Inline.php @@ -193,7 +193,7 @@ class Inline */ 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))); } diff --git a/src/Symfony/Components/Yaml/Parser.php b/src/Symfony/Components/Yaml/Parser.php index ef495d6c22..ac26d420e6 100644 --- a/src/Symfony/Components/Yaml/Parser.php +++ b/src/Symfony/Components/Yaml/Parser.php @@ -52,7 +52,7 @@ class Parser 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(); @@ -67,8 +67,8 @@ class Parser } $isRef = $isInPlace = $isProcessed = false; - if (preg_match('#^\-((?P\s+)(?P.+?))?\s*$#', $this->currentLine, $values)) { - if (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#', $values['value'], $matches)) { + if (preg_match('#^\-((?P\s+)(?P.+?))?\s*$#u', $this->currentLine, $values)) { + if (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } @@ -82,7 +82,7 @@ class Parser } else { if (isset($values['leadspaces']) && ' ' == $values['leadspaces'] - && preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P.+?))?\s*$#', $values['value'], $matches) + && preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{].*?) *\:(\s+(?P.+?))?\s*$#u', $values['value'], $matches) ) { // this is a compact notation element, add to next block and parse $c = $this->getRealCurrentLineNb(); @@ -99,7 +99,7 @@ class Parser $data[] = $this->parseValue($values['value']); } } - } else if (preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P.+?))?\s*$#', $this->currentLine, $values)) { + } else if (preg_match('#^(?P'.Inline::REGEX_QUOTED_STRING.'|[^ \'"].*?) *\:(\s+(?P.+?))?\s*$#u', $this->currentLine, $values)) { $key = Inline::parseScalar($values['key']); if ('<<' === $key) { @@ -137,7 +137,7 @@ class Parser $isProcessed = $merged; } - } else if (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#', $values['value'], $matches)) { + } else if (isset($values['value']) && preg_match('#^&(?P[^ ]+) *(?P.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } @@ -375,7 +375,7 @@ class Parser return ''; } - if (!preg_match('#^(?P'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P.*)$#', $this->currentLine, $matches)) { + if (!preg_match('#^(?P'.($indentation ? str_repeat(' ', $indentation) : ' +').')(?P.*)$#u', $this->currentLine, $matches)) { $this->moveToPreviousLine(); return ''; @@ -388,7 +388,7 @@ class Parser while ($this->currentLineNb + 1 < count($this->lines)) { $this->moveToNextLine(); - if (preg_match('#^(?P {'.strlen($textIndent).',})(?P.+)$#', $this->currentLine, $matches)) { + if (preg_match('#^(?P {'.strlen($textIndent).',})(?P.+)$#u', $this->currentLine, $matches)) { if (' ' == $separator && $previousIndent != $matches['indent']) { $text = substr($text, 0, -1)."\n"; } @@ -500,11 +500,11 @@ class Parser // 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");