Permalink
Browse files

[Yaml] added exceptions when non-utf8 encoding is detected

encoding is detected using the `mb_detect_encoding()`-function
in strict-mode. Checking is done before the parsing starts.
Without this patch, the calls to `preg_replace()` using the
'u'-modifier would cause the non-utf8-string being processed
to be empty when parsing starts which makes the parsing return
no result.
  • Loading branch information...
1 parent 3d86445 commit 8c5992e4bad2482bb8c28f0475c536eec57772f8 Martin Schuhfuss committed May 12, 2011
Showing with 4 additions and 0 deletions.
  1. +4 −0 Parser.php
View
@@ -48,6 +48,10 @@ public function parse($value)
$this->currentLine = '';
$this->lines = explode("\n", $this->cleanup($value));
+ if (function_exists('mb_detect_encoding') && false === mb_detect_encoding($value, 'UTF-8', true)) {
+ throw new ParserException('The input does not appear to be valid UTF8.');
+ }
+
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('UTF-8');

0 comments on commit 8c5992e

Please sign in to comment.