Skip to content

Commit f7b172a

Browse files
feat: escape html in view params by default
1 parent ad6f7e6 commit f7b172a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/View.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ public function __construct(string $path = '')
7777
*
7878
* @throws Exception
7979
*/
80-
public function setParam(string $key, mixed $value): static
80+
public function setParam(string $key, mixed $value, bool $escapeHtml = true): static
8181
{
8282
if (\strpos($key, '.') !== false) {
8383
throw new Exception('$key can\'t contain a dot "." character');
8484
}
8585

86+
if (is_string($value) && $escapeHtml) {
87+
$value = htmlspecialchars($value, encoding: 'UTF-8');
88+
}
89+
8690
$this->params[$key] = $value;
8791

8892
return $this;

0 commit comments

Comments
 (0)