Skip to content

Commit

Permalink
[#14553] - Allow null in escapeHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Nov 22, 2019
1 parent 4ac8ee8 commit cef5d49
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions phalcon/Escaper.zep
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Escaper implements EscaperInterface
/**
* Escapes a HTML string. Internally uses htmlspecialchars
*/
public function escapeHtml(string text) -> string
public function escapeHtml(string text = null) -> string
{
return htmlspecialchars(
text,
Expand All @@ -134,7 +134,7 @@ class Escaper implements EscaperInterface
/**
* Escapes a HTML attribute string
*/
public function escapeHtmlAttr(string attribute) -> string
public function escapeHtmlAttr(string attribute = null) -> string
{
return htmlspecialchars(
attribute,
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/Escaper/EscapeHtmlAttrCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ private function escaperEscapeHtmlAttrProvider(): array
'expected' => 'That's right',
'text' => "That's right",
],
[
'htmlQuoteType' => ENT_HTML401,
'expected' => '',
'text' => null,
],

[
'htmlQuoteType' => ENT_XML1,
'expected' => '',
'text' => null,
],

[
'htmlQuoteType' => ENT_XHTML,
'expected' => '',
'text' => null,
],

[
'htmlQuoteType' => ENT_HTML5,
'expected' => '',
'text' => null,
],
];
}
}
18 changes: 18 additions & 0 deletions tests/unit/Escaper/EscapeHtmlCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ public function escaperEscapeHtml(UnitTester $I)
$escaper->escapeHtml('<h1></h1>')
);
}

/**
* Tests Phalcon\Escaper :: escapeHtml() - null
*
* @author Phalcon Team <[email protected]>
* @since 2019-11-22
*/
public function escaperEscapeHtmlNull(UnitTester $I)
{
$I->wantToTest('Escaper - escapeHtml() - null');

$escaper = new Escaper();

$I->assertEquals(
'',
$escaper->escapeHtml(null)
);
}
}

0 comments on commit cef5d49

Please sign in to comment.