Skip to content

Commit

Permalink
Filters: compatibility with JS binding
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 8, 2021
1 parent baf2071 commit 108d4a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Latte/Runtime/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public static function escapeHtml($s): string
*/
public static function escapeHtmlText($s): string
{
return $s instanceof HtmlStringable || $s instanceof \Nette\Utils\IHtmlString
? $s->__toString(true)
: htmlspecialchars((string) $s, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
if ($s instanceof HtmlStringable || $s instanceof \Nette\Utils\IHtmlString) {
return $s->__toString(true);
}
$s = htmlspecialchars((string) $s, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
$s = str_replace('{{', '{<!-- -->{', $s);
return $s;
}


Expand Down
3 changes: 3 additions & 0 deletions tests/Latte/Filters.escapeHtmlText().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ Assert::same('`hello', Filters::escapeHtmlText('`hello'));
// invalid UTF-8
Assert::same("foo \u{FFFD} bar", Filters::escapeHtmlText("foo \u{D800} bar")); // invalid codepoint high surrogates
Assert::same("foo \u{FFFD}\" bar", Filters::escapeHtmlText("foo \xE3\x80\x22 bar")); // stripped UTF

// JS
Assert::same('hello {<!-- -->{ worlds }}', Filters::escapeHtmlText('hello {{ worlds }}'));

0 comments on commit 108d4a7

Please sign in to comment.