From 108d4a743a5ded6b1609ad0689ca564d41acc1ab Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 4 Feb 2021 15:00:32 +0100 Subject: [PATCH] Filters: compatibility with JS binding thx @janbarasek --- src/Latte/Runtime/Filters.php | 9 ++++++--- tests/Latte/Filters.escapeHtmlText().phpt | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Latte/Runtime/Filters.php b/src/Latte/Runtime/Filters.php index 988d0b838..c81a6c057 100644 --- a/src/Latte/Runtime/Filters.php +++ b/src/Latte/Runtime/Filters.php @@ -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; } diff --git a/tests/Latte/Filters.escapeHtmlText().phpt b/tests/Latte/Filters.escapeHtmlText().phpt index ed35074f2..1e8e76be5 100644 --- a/tests/Latte/Filters.escapeHtmlText().phpt +++ b/tests/Latte/Filters.escapeHtmlText().phpt @@ -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 }}'));