From 6b6d515030808a9cff0d3367111de51129395815 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 28 Mar 2010 15:10:36 +0200 Subject: [PATCH] fixed the Lexer when mbstring.func_overload is used with an mbstring.internal_encoding different from ASCII (closes #32) --- CHANGELOG | 1 + lib/Twig/Lexer.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 896a8a1..65d8c1e 100644 --- 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 diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 66d82b4..7d0a85f 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -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()); } -- 1.7.2.5