File tree 3 files changed +57
-1
lines changed
3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ Yii Framework 2 Change Log
6
6
7
7
- Bug #14663 : Do not convert int to string if database type of a column is numeric (egorrishe)
8
8
- Bug #18650 : Refactor ` framework/assets/yii.activeForm.js ` arrow function into traditional function for IE11 compatibility (marcovtwout)
9
+ - Bug #18749 : Fix ` yii\web\ErrorHandler::encodeHtml() ` to support strings with invalid UTF symbols (vjik)
9
10
- Enh #18724 : Allow jQuery 3.6 to be installed (marcovtwout)
10
11
- Enh #18628 : Added strings "software", and "hardware" to ` $specials ` array in ` yii\helpers\BaseInflector ` (kjusupov)
11
12
- Enh #18653 : Added method ` yii\helpers\BaseHtml::getInputIdByName() ` (WinterSilence)
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ protected function convertExceptionToArray($exception)
180
180
*/
181
181
public function htmlEncode ($ text )
182
182
{
183
- return htmlspecialchars ($ text , ENT_QUOTES , 'UTF-8 ' );
183
+ return htmlspecialchars ($ text , ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_HTML5 , 'UTF-8 ' );
184
184
}
185
185
186
186
/**
Original file line number Diff line number Diff line change @@ -79,6 +79,61 @@ public function testRenderCallStackItem()
79
79
80
80
$ this ->assertContains ('<a href="netbeans://open?file= ' . $ file . '&line=63"> ' , $ out );
81
81
}
82
+
83
+ public function dataHtmlEncode ()
84
+ {
85
+ return [
86
+ [
87
+ "a \t=<>& \"' \x80` \n" ,
88
+ "a \t=<>& \"'�` \n" ,
89
+ ],
90
+ [
91
+ '<b>test</b> ' ,
92
+ '<b>test</b> ' ,
93
+ ],
94
+ [
95
+ '"hello" ' ,
96
+ '"hello" ' ,
97
+ ],
98
+ [
99
+ "'hello world' " ,
100
+ "'hello world' " ,
101
+ ],
102
+ [
103
+ 'Chip&Dale ' ,
104
+ 'Chip&amp;Dale ' ,
105
+ ],
106
+ [
107
+ "\t\$x=24; " ,
108
+ "\t\$x=24; " ,
109
+ ],
110
+ ];
111
+ }
112
+
113
+ /**
114
+ * @dataProvider dataHtmlEncode
115
+ */
116
+ public function testHtmlEncode ($ text , $ expected )
117
+ {
118
+ $ handler = Yii::$ app ->getErrorHandler ();
119
+
120
+ $ this ->assertSame ($ expected , $ handler ->htmlEncode ($ text ));
121
+ }
122
+
123
+ public function testHtmlEncodeWithUnicodeSequence ()
124
+ {
125
+ if (PHP_VERSION_ID < 70000 ) {
126
+ $ this ->markTestSkipped ('Can not be tested on PHP < 7.0 ' );
127
+ return ;
128
+ }
129
+
130
+ $ handler = Yii::$ app ->getErrorHandler ();
131
+
132
+ $ text = "a \t=<>& \"' \x80\u{20bd}` \u{000a}\u{000c}\u{0000}" ;
133
+ $ expected = "a \t=<>& \"'�₽` \n\u{000c}\u{0000}" ;
134
+
135
+ $ this ->assertSame ($ expected , $ handler ->htmlEncode ($ text ));
136
+ }
82
137
}
83
138
84
139
class ErrorHandler extends \yii \web \ErrorHandler
You can’t perform that action at this time.
0 commit comments