Skip to content

Commit b433316

Browse files
committed
[#16123] - corrected attributes escaping - removed array/string check
1 parent de6e902 commit b433316

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

phalcon/Html/Escaper.zep

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ class Escaper implements EscaperInterface
6666
{
6767
var key, result, value;
6868

69-
if (typeof input !== "string" && typeof input !== "array") {
70-
throw new Exception("Input must be an array or a string");
71-
}
72-
73-
if (typeof input === "string") {
74-
return this->phpHtmlSpecialChars(input);
69+
if likely (typeof input !== "array") {
70+
return this->phpHtmlSpecialChars((string) input);
7571
}
7672

7773
let result = "";
@@ -86,11 +82,11 @@ class Escaper implements EscaperInterface
8682
let value = implode(" ", value);
8783
}
8884

89-
let result .= this->phpHtmlSpecialChars(key);
85+
let result .= this->phpHtmlSpecialChars((string) key);
9086

9187
if (true !== value) {
9288
let result .= "=\""
93-
. this->phpHtmlSpecialChars(value)
89+
. this->phpHtmlSpecialChars((string) value)
9490
. "\"";
9591
}
9692

tests/unit/Html/Escaper/AttributesCest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ private function escaperEscapeHtmlAttrProvider(): array
7777
'expected' => 'That's right',
7878
'text' => "That's right",
7979
],
80+
[
81+
'htmlQuoteType' => ENT_HTML5,
82+
'expected' => '10',
83+
'text' => 10,
84+
],
85+
[
86+
'htmlQuoteType' => ENT_HTML5,
87+
'expected' => 'maxlength="10" cols="5" rows="3" min="1" max="100"',
88+
'text' => [
89+
'maxlength' => 10,
90+
'cols' => 5,
91+
'rows' => 3,
92+
'min' => 1,
93+
'max' => 100,
94+
'notPrinted' => false,
95+
'notPrinted2' => null,
96+
],
97+
],
8098
[
8199
'htmlQuoteType' => ENT_HTML5,
82100
'expected' => 'text="Ferrari Ford Dodge"',

0 commit comments

Comments
 (0)