Skip to content

Commit

Permalink
test: add tests for escaped html
Browse files Browse the repository at this point in the history
  • Loading branch information
TorstenDittmann committed Jan 8, 2024
1 parent f7b172a commit 5b62a82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function setParam(string $key, mixed $value, bool $escapeHtml = true): st
}

if (is_string($value) && $escapeHtml) {
$value = htmlspecialchars($value, encoding: 'UTF-8');
$value = \htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}

$this->params[$key] = $value;
Expand Down
6 changes: 6 additions & 0 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public function testCanFilterNewLinesToParagraphs()
{
$this->assertEquals('<p>line1</p><p>line2</p>', $this->view->print("line1\n\nline2", View::FILTER_NL2P));
}

public function testCanSetParamWithEscapedHtml()
{
$this->view->setParam('key', '<html>value</html>');
$this->assertEquals('&lt;html&gt;value&lt;/html&gt;', $this->view->getParam('key', 'default'));
}
}

0 comments on commit 5b62a82

Please sign in to comment.