diff --git a/flight/template/View.php b/flight/template/View.php index fae471f..17622fd 100644 --- a/flight/template/View.php +++ b/flight/template/View.php @@ -191,7 +191,7 @@ class View */ public function e(string $str): string { - $value = \htmlentities($str); + $value = \htmlentities($str, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); echo $value; return $value; } diff --git a/tests/ViewTest.php b/tests/ViewTest.php index e57afd0..56a6e0e 100644 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -133,6 +133,17 @@ class ViewTest extends TestCase $this->assertEquals('script', $result); } + public function testEEscapesSingleQuote(): void + { + $expected = htmlentities("'", ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); + + $this->expectOutputString($expected); + $result = $this->view->e("'"); + + $this->assertEquals($expected, $result); + $this->assertEquals(''', $result); + } + public function testNormalizePath(): void { $viewMock = new class extends View