Skip to content

Commit

Permalink
BlockMacros: dynamic blocks with content-types html & htmlattr are co…
Browse files Browse the repository at this point in the history
…mpatible [Closes #146]
  • Loading branch information
dg committed Jan 18, 2017
1 parent 7b1ce98 commit 05187e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Latte/Macros/BlockMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ public function macroBlock(MacroNode $node, PhpWriter $writer)
if ($node->name === 'define') {
$node->closingCode = '<?php ?>';
} else {
if ($node->modifiers) {
if (Helpers::startsWith((string) $node->context[1], Latte\Compiler::CONTEXT_HTML_ATTRIBUTE)) {
$node->context[1] = '';
$node->modifiers .= '|escape';
} elseif ($node->modifiers) {
$node->modifiers .= '|escape';
}
$node->closingCode = $writer->write('<?php $this->renderBlock(%raw, get_defined_vars()'
Expand Down
7 changes: 6 additions & 1 deletion tests/Latte/contentType.compatibility.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ test(function () {
$latte->renderToString('{include main}{block main}<div>foo</div>{/block}')
);

Assert::same(
'a"B<p title="a&quot;B"></p>',
$latte->renderToString('{block main}a"B{/block}{var $name = main}<p title="{block $name}xx{/block}"></p>')
);

Assert::same(
'<!-- - - - -->---',
$latte->renderToString('<!--{include main}-->{block main}---{/block}')
Expand Down Expand Up @@ -340,7 +345,7 @@ Assert::error(function () use ($latte) {
},E_USER_WARNING, 'Filter |upper is called with incompatible content type HTML, try to prepend |stripHtml.');

Assert::same('<p> " &lt;</p>', $latte->renderToString('context1c'));
Assert::same('<p title="<hr> &quot;"</p>', $latte->renderToString('context2'));
Assert::same('<p title="&lt;hr&gt; &quot;"</p>', $latte->renderToString('context2'));
Assert::same('<p title=" &quot;"></p>', $latte->renderToString('context2a'));
Assert::same('<!--<hr> &lt;-->', $latte->renderToString('context6'));

Expand Down
2 changes: 1 addition & 1 deletion tests/Latte/expected/BlockMacros.dynamicblock.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Template%a% extends Latte\Runtime\Template
$this->blockQueue["strip$name"][] = [$this, 'blockStrip_name'];
$this->renderBlock("strip$name", get_defined_vars(), function ($s, $type) {
$_fi = new LR\FilterInfo($type);
return $this->filters->filterContent('striptags', $_fi, $s);
return LR\Filters::convertTo($_fi, 'html', $this->filters->filterContent('striptags', $_fi, $s));
});
?>

Expand Down

0 comments on commit 05187e9

Please sign in to comment.