[Yaml] fixed YAML parser when mbstring.func_overload is used with an mbstring.internal_encoding different from ASCII

This commit is contained in:
Fabien Potencier 2010-03-29 12:40:22 +02:00
parent 4bd865de67
commit dc1bc88279
2 changed files with 34 additions and 3 deletions

View File

@ -37,15 +37,30 @@ class Inline
return ''; return '';
} }
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
{
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
switch ($value[0]) switch ($value[0])
{ {
case '[': case '[':
return self::parseSequence($value); $result = self::parseSequence($value);
break;
case '{': case '{':
return self::parseMapping($value); $result = self::parseMapping($value);
break;
default: default:
return self::parseScalar($value); $result = self::parseScalar($value);
} }
if (isset($mbEncoding))
{
mb_internal_encoding($mbEncoding);
}
return $result;
} }
/** /**

View File

@ -50,6 +50,12 @@ class Parser
$this->currentLine = ''; $this->currentLine = '';
$this->lines = explode("\n", $this->cleanup($value)); $this->lines = explode("\n", $this->cleanup($value));
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
{
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
$data = array(); $data = array();
while ($this->moveToNextLine()) while ($this->moveToNextLine())
{ {
@ -220,6 +226,11 @@ class Parser
} }
} }
if (isset($mbEncoding))
{
mb_internal_encoding($mbEncoding);
}
return $value; return $value;
} }
@ -253,6 +264,11 @@ class Parser
} }
} }
if (isset($mbEncoding))
{
mb_internal_encoding($mbEncoding);
}
return empty($data) ? null : $data; return empty($data) ? null : $data;
} }