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()
public function count()
{
- return strlen($this->content);
+ return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content);
}
}
$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())");
}
}
$compiler
->raw("new Twig_Markup(")
->subcompile($this->getNode('values'))
- ->raw(")")
+ ->raw(", \$this->env->getCharset())")
;
} else {
$compiler->subcompile($this->getNode('values'));
$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;
{{ 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"
{{ 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
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
$tests[] = array($node, <<<EOF
ob_start();
echo "foo";
-\$context["foo"] = new Twig_Markup(ob_get_clean());
+\$context["foo"] = new Twig_Markup(ob_get_clean(), \$this->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);