Skip to content

Commit

Permalink
Filters: compatibility with JS binding II.
Browse files Browse the repository at this point in the history
- when {{ is used inside a <script type="text/template"> it can either be written as entity &#123; OR with comment
- when {{ is used in HTML it must be written with comment (which cannot be used in HTML attribute)
  • Loading branch information
dg committed Oct 26, 2021
1 parent 7ca3e68 commit a82fd99
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Latte/Runtime/Filters.php
Expand Up @@ -48,7 +48,7 @@ public static function escapeHtmlText($s): string
return $s->__toString(true);
}
$s = htmlspecialchars((string) $s, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
$s = str_replace('{{', '{<!-- -->{', $s);
$s = strtr($s, ['{{' => '{<!-- -->{', '{' => '&#123;']);
return $s;
}

Expand All @@ -65,7 +65,9 @@ public static function escapeHtmlAttr($s, bool $double = true): string
if (strpos($s, '`') !== false && strpbrk($s, ' <>"\'') === false) {
$s .= ' '; // protection against innerHTML mXSS vulnerability nette/nette#1496
}
return htmlspecialchars($s, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE, 'UTF-8', $double);
$s = htmlspecialchars($s, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE, 'UTF-8', $double);
$s = str_replace('{', '&#123;', $s);
return $s;
}


Expand Down

0 comments on commit a82fd99

Please sign in to comment.