$compiler->subcompile($this->getNode('names'), false);
if ($this->getAttribute('capture')) {
- $compiler->raw(" = new Twig_Markup(ob_get_clean(), \$this->env->getCharset())");
+ $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())");
}
}
} else {
if ($this->getAttribute('safe')) {
$compiler
- ->raw("new Twig_Markup(")
+ ->raw("('' === \$tmp = ")
->subcompile($this->getNode('values'))
- ->raw(", \$this->env->getCharset())")
+ ->raw(") ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset())")
;
} else {
$compiler->subcompile($this->getNode('values'));
// hack to be removed when macro calls are refactored
if ($object instanceof Twig_TemplateInterface) {
- return new Twig_Markup($ret, $this->env->getCharset());
+ return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset());
}
return $ret;
$tests[] = array($node, <<<EOF
ob_start();
echo "foo";
-\$context["foo"] = new Twig_Markup(ob_get_clean(), \$this->env->getCharset());
+\$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$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", $this->env->getCharset());');
+ $tests[] = array($node, '$context["foo"] = (\'\' === $tmp = "foo") ? \'\' : new Twig_Markup($tmp, $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);