fixed the Lexer when mbstring.func_overload is used with an mbstring.internal_encodin...
authorFabien Potencier <fabien.potencier@gmail.com>
Sun, 28 Mar 2010 13:10:36 +0000 (15:10 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Sun, 28 Mar 2010 13:10:36 +0000 (15:10 +0200)
CHANGELOG
lib/Twig/Lexer.php

index 896a8a1..65d8c1e 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
 * 0.9.6-DEV
 
+ * fixed the Lexer when mbstring.func_overload is used with an mbstring.internal_encoding different from ASCII
  * added a long-syntax for the set tag ({% set foo %}...{% endset %})
  * unit tests are now powered by PHPUnit
  * added support for gettext via the `i18n` extension
index 66d82b4..7d0a85f 100644 (file)
@@ -59,6 +59,12 @@ class Twig_Lexer implements Twig_LexerInterface
    */
   public function tokenize($code, $filename = 'n/a')
   {
+    if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
+    {
+      $mbEncoding = mb_internal_encoding();
+      mb_internal_encoding('ASCII');
+    }
+
     $this->code = preg_replace('/(\r\n|\r|\n)/', "\n", $code);
     $this->filename = $filename;
     $this->cursor = 0;
@@ -78,6 +84,11 @@ class Twig_Lexer implements Twig_LexerInterface
       $end = $token->getType() === Twig_Token::EOF_TYPE;
     }
 
+    if (isset($mbEncoding))
+    {
+      mb_internal_encoding($mbEncoding);
+    }
+
     return new Twig_TokenStream($tokens, $this->filename, $this->env->getTrimBlocks());
   }