Visitar URL original
fix: escape single quotes in View::e() by ambrose5773 · Pull Request #728 · flightphp/core · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: escape single quotes in View::e()
Pass ENT_QUOTES|ENT_SUBSTITUTE and UTF-8 to htmlentities so single-quoted
attributes are escaped on PHP 7.4/8.0 as well as 8.1+.
  • Loading branch information
ambrose5773 committed Sep 4, 2026
commit 6b8d2f9880ca21f89a12565b278fc9d0e00f2df3
2 changes: 1 addition & 1 deletion flight/template/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function getTemplate(string $file): string
*/
public function e(string $str): string
{
$value = \htmlentities($str);
$value = \htmlentities($str, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
echo $value;
return $value;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public function testeNoNeedToEscape(): void
$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
Expand Down