From: Fabien Potencier Date: Mon, 9 Jan 2012 19:48:27 +0000 (+0100) Subject: fixed charset for previous commit X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=fee85f2f1d9b5f3a9b2d6859c56d6229f79ae909;p=konrad%2Ftwig.git fixed charset for previous commit --- diff --git a/lib/Twig/Markup.php b/lib/Twig/Markup.php index 8a7a65f..7099b29 100644 --- a/lib/Twig/Markup.php +++ b/lib/Twig/Markup.php @@ -18,10 +18,12 @@ class Twig_Markup implements Countable { protected $content; + protected $charset; - public function __construct($content) + public function __construct($content, $charset) { $this->content = (string) $content; + $this->charset = $charset; } public function __toString() @@ -31,6 +33,6 @@ class Twig_Markup implements Countable public function count() { - return strlen($this->content); + return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content); } } diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index 9913664..098ed40 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -67,7 +67,7 @@ class Twig_Node_Set extends Twig_Node $compiler->subcompile($this->getNode('names'), false); if ($this->getAttribute('capture')) { - $compiler->raw(" = new Twig_Markup(ob_get_clean())"); + $compiler->raw(" = new Twig_Markup(ob_get_clean(), \$this->env->getCharset())"); } } @@ -89,7 +89,7 @@ class Twig_Node_Set extends Twig_Node $compiler ->raw("new Twig_Markup(") ->subcompile($this->getNode('values')) - ->raw(")") + ->raw(", \$this->env->getCharset())") ; } else { $compiler->subcompile($this->getNode('values')); diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 7d09598..86ca5c6 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -428,7 +428,7 @@ abstract class Twig_Template implements Twig_TemplateInterface $ret = call_user_func_array(array($object, $method), $arguments); if ($object instanceof Twig_TemplateInterface) { - return new Twig_Markup($ret); + return new Twig_Markup($ret, $this->env->getCharset()); } return $ret; diff --git a/test/Twig/Tests/Fixtures/filters/json_encode.test b/test/Twig/Tests/Fixtures/filters/json_encode.test index 776a631..1738d40 100644 --- a/test/Twig/Tests/Fixtures/filters/json_encode.test +++ b/test/Twig/Tests/Fixtures/filters/json_encode.test @@ -5,7 +5,7 @@ {{ foo|json_encode|raw }} {{ [foo, "foo"]|json_encode|raw }} --DATA-- -return array('foo' => new Twig_Markup('foo')) +return array('foo' => new Twig_Markup('foo', 'UTF-8')) --EXPECT-- "foo" "foo" diff --git a/test/Twig/Tests/Fixtures/filters/length.test b/test/Twig/Tests/Fixtures/filters/length.test index 56217ff..6de51e0 100644 --- a/test/Twig/Tests/Fixtures/filters/length.test +++ b/test/Twig/Tests/Fixtures/filters/length.test @@ -6,9 +6,9 @@ {{ number|length }} {{ markup|length }} --DATA-- -return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000, 'markup' => new Twig_Markup('test')) +return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000, 'markup' => new Twig_Markup('été', 'UTF-8')) --EXPECT-- 2 3 4 -4 +3 diff --git a/test/Twig/Tests/Fixtures/tests/empty.test b/test/Twig/Tests/Fixtures/tests/empty.test index 651eba7..a776d03 100644 --- a/test/Twig/Tests/Fixtures/tests/empty.test +++ b/test/Twig/Tests/Fixtures/tests/empty.test @@ -30,7 +30,7 @@ class CountableStub implements Countable return array( 'foo' => '', 'bar' => null, 'foobar' => false, 'array' => array(), 'zero' => 0, 'string' => '0', 'countable_empty' => new CountableStub(array()), 'countable_not_empty' => new CountableStub(array(1, 2)), - 'markup_empty' => new Twig_Markup(''), 'markup_not_empty' => new Twig_Markup('test'), + 'markup_empty' => new Twig_Markup('', 'UTF-8'), 'markup_not_empty' => new Twig_Markup('test', 'UTF-8'), ); --EXPECT-- ok diff --git a/test/Twig/Tests/Node/SetTest.php b/test/Twig/Tests/Node/SetTest.php index d40b90d..4c59854 100644 --- a/test/Twig/Tests/Node/SetTest.php +++ b/test/Twig/Tests/Node/SetTest.php @@ -51,14 +51,14 @@ class Twig_Tests_Node_SetTest extends Twig_Tests_Node_TestCase $tests[] = array($node, <<env->getCharset()); EOF ); $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0)), array(), 0); $values = new Twig_Node_Text('foo', 0); $node = new Twig_Node_Set(true, $names, $values, 0); - $tests[] = array($node, '$context["foo"] = new Twig_Markup("foo");'); + $tests[] = array($node, '$context["foo"] = new Twig_Markup("foo", $this->env->getCharset());'); $names = new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 0), new Twig_Node_Expression_AssignName('bar', 0)), array(), 0); $values = new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 0), new Twig_Node_Expression_Name('bar', 0)), array(), 0);