Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T14553 escaper nulls #14554

Merged
merged 2 commits into from
Nov 22, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Fixed `Phalcon\Security::getRandomBytes` to return `int` [#14551](https://github.com/phalcon/cphalcon/issues/14551)
- Fixed `Phalcon\Security` to use `10` as the default work factor [#14551](https://github.com/phalcon/cphalcon/issues/14551)
- Fixed `Phalcon\Helper\Arr::validateAny` and `Phalcon\Helper\Arr::validateAll`to use `null` as default for the callback method [#14551](https://github.com/phalcon/cphalcon/issues/14551)
- Fixed `Phalcon\Escaper::escapeHtml` and `Phalcon\Escaper::escapeHtmlAttr` to allow `null` values [#14553](https://github.com/phalcon/cphalcon/issues/14553)

# [4.0.0-rc.r3](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-rc.3) (2019-11-16)
## Added
Expand Down
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)
);
}
}