Skip to content

Commit

Permalink
fix lỗi Argument 1 passed to Laminas\Escaper\Escaper::escapeHtml() mu…
Browse files Browse the repository at this point in the history
…st be of the type string, null given
  • Loading branch information
hungnguyenhp committed Aug 2, 2023
1 parent 6c8499e commit b9af73f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
46 changes: 39 additions & 7 deletions helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ function is_php($version)
*
* @return string
*/
function escapeHtml($string = '')
function escapeHtml($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeHtml($string);
}
}
Expand All @@ -57,8 +61,12 @@ function escapeHtml($string = '')
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 09/21/2021 00:05
*/
function htmlEscape($string = '')
function htmlEscape($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeHtml($string);
}
}
Expand All @@ -73,8 +81,12 @@ function htmlEscape($string = '')
*
* @return string
*/
function escapeHtmlAttr($string = '')
function escapeHtmlAttr($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeHtmlAttribute($string);
}
}
Expand All @@ -89,8 +101,12 @@ function escapeHtmlAttr($string = '')
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 09/23/2021 44:34
*/
function escapeHtmlAttribute($string = '')
function escapeHtmlAttribute($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeHtmlAttribute($string);
}
}
Expand All @@ -105,8 +121,12 @@ function escapeHtmlAttribute($string = '')
*
* @return string
*/
function escapeJs($string = '')
function escapeJs($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeJs($string);
}
}
Expand All @@ -123,6 +143,10 @@ function escapeJs($string = '')
*/
function escapeInputVar($var)
{
if ($var === null) {
return null;
}

return (new Escape())->escapeInput($var);
}
}
Expand Down Expand Up @@ -153,8 +177,12 @@ function escape_input_var($var)
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 09/20/2021 58:14
*/
function escapeCss($string = '')
function escapeCss($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeCss($string);
}
}
Expand All @@ -169,8 +197,12 @@ function escapeCss($string = '')
*
* @return string
*/
function escapeUrl($string = '')
function escapeUrl($string)
{
if ($string === null) {
return null;
}

return (new Escape())->escapeUrl($string);
}
}
Expand Down
33 changes: 26 additions & 7 deletions src/Escape.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class Escape
{
const VERSION = '1.0.8';
const VERSION = '1.0.9';

/**
* Character set
Expand Down Expand Up @@ -376,8 +376,11 @@ public function sanitizeFilename($str, $relative_path = false)
*
* @return string
*/
public function escapeHtml($string = '')
public function escapeHtml($string)
{
if ($string === null) {
return null;
}
$escape = new Escaper('utf-8');

return $escape->escapeHtml($string);
Expand All @@ -393,8 +396,12 @@ public function escapeHtml($string = '')
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 09/21/2021 00:05
*/
public function htmlEscape($string = '')
public function htmlEscape($string)
{
if ($string === null) {
return null;
}

return $this->escapeHtml($string);
}

Expand All @@ -408,8 +415,11 @@ public function htmlEscape($string = '')
*
* @return string
*/
public function escapeHtmlAttribute($string = '')
public function escapeHtmlAttribute($string)
{
if ($string === null) {
return null;
}
$escape = new Escaper('utf-8');

return $escape->escapeHtmlAttr($string);
Expand All @@ -425,8 +435,11 @@ public function escapeHtmlAttribute($string = '')
*
* @return string
*/
public function escapeJs($string = '')
public function escapeJs($string)
{
if ($string === null) {
return null;
}
$escape = new Escaper('utf-8');

return $escape->escapeJs($string);
Expand All @@ -442,8 +455,11 @@ public function escapeJs($string = '')
* @copyright: 713uk13m <dev@nguyenanhung.com>
* @time : 09/20/2021 58:14
*/
public function escapeCss($string = '')
public function escapeCss($string)
{
if ($string === null) {
return null;
}
$escape = new Escaper('utf-8');

return $escape->escapeCss($string);
Expand All @@ -459,8 +475,11 @@ public function escapeCss($string = '')
*
* @return string
*/
public function escapeUrl($string = '')
public function escapeUrl($string)
{
if ($string === null) {
return null;
}
$escape = new Escaper('utf-8');

return $escape->escapeUrl($string);
Expand Down

0 comments on commit b9af73f

Please sign in to comment.