@@ -64,8 +64,11 @@ public static function provideSanitizeHead()
6464 }
6565
6666 #[DataProvider('provideSanitizeBody ' )]
67- public function testSanitizeBody (string $ input , string $ expected )
67+ public function testSanitizeBody (string $ input , string $ expected, ? string $ legacyExpected = null )
6868 {
69+ if (\PHP_VERSION_ID < 80400 ) {
70+ $ expected = $ legacyExpected ?? $ expected ;
71+ }
6972 $ this ->assertSame ($ expected , $ this ->createSanitizer ()->sanitize ($ input ));
7073 }
7174
@@ -83,6 +86,7 @@ public static function provideSanitizeBody()
8386 ],
8487 [
8588 '< Hello ' ,
89+ '< Hello ' ,
8690 ' Hello ' ,
8791 ],
8892 [
@@ -127,6 +131,7 @@ public static function provideSanitizeBody()
127131 ],
128132 [
129133 '<<a href="javascript:evil"/>a href="javascript:evil"/> ' ,
134+ '<<a>a href="javascript:evil"/></a> ' ,
130135 '<a>a href="javascript:evil"/></a> ' ,
131136 ],
132137 [
@@ -163,10 +168,12 @@ public static function provideSanitizeBody()
163168 ],
164169 [
165170 '<<img src="javascript:evil"/>iframe src="javascript:evil"/> ' ,
171+ '<<img />iframe src="javascript:evil"/> ' ,
166172 '<img />iframe src="javascript:evil"/> ' ,
167173 ],
168174 [
169175 '<<img src="javascript:evil"/>img src="javascript:evil"/> ' ,
176+ '<<img />img src="javascript:evil"/> ' ,
170177 '<img />img src="javascript:evil"/> ' ,
171178 ],
172179 [
@@ -211,10 +218,12 @@ public static function provideSanitizeBody()
211218 ],
212219 [
213220 '<IMG SRC=javascript:alert('XSS')> ' ,
221+ '<img /> ' ,
214222 '<img src="&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041" /> ' ,
215223 ],
216224 [
217225 '<IMG SRC=javascript:alert('XSS')> ' ,
226+ '<img /> ' ,
218227 '<img src="&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29" /> ' ,
219228 ],
220229 [
@@ -233,10 +242,6 @@ public static function provideSanitizeBody()
233242 '<svg/onload=alert( \'XSS \')> ' ,
234243 '' ,
235244 ],
236- [
237- '<BODY BACKGROUND="javascript:alert( \'XSS \')"> ' ,
238- '<body></body> ' ,
239- ],
240245 [
241246 '<BGSOUND SRC="javascript:alert( \'XSS \');"> ' ,
242247 '<bgsound></bgsound> ' ,
@@ -350,10 +355,6 @@ public static function provideSanitizeBody()
350355 'Lorem ipsum <br>dolor sit amet <br />consectetur adipisicing. ' ,
351356 'Lorem ipsum <br />dolor sit amet <br />consectetur adipisicing. ' ,
352357 ],
353- [
354- '<caption>Lorem ipsum</caption> ' ,
355- '<caption>Lorem ipsum</caption> ' ,
356- ],
357358 [
358359 '<code>Lorem ipsum</code> ' ,
359360 '<code>Lorem ipsum</code> ' ,
@@ -529,41 +530,84 @@ public static function provideSanitizeBody()
529530 ],
530531 [
531532 '<table>Lorem ipsum</table> ' ,
533+ 'Lorem ipsum<table></table> ' ,
532534 '<table>Lorem ipsum</table> ' ,
533535 ],
536+ [
537+ '<ul>Lorem ipsum</ul> ' ,
538+ '<ul>Lorem ipsum</ul> ' ,
539+ ],
540+ ];
541+
542+ foreach ($ cases as $ case ) {
543+ yield $ case [0 ] => $ case ;
544+ }
545+ }
546+
547+ #[DataProvider('provideSanitizeTable ' )]
548+ public function testSanitizeTable (string $ input , string $ expected , ?string $ legacyExpected = null )
549+ {
550+ if (\PHP_VERSION_ID < 80400 ) {
551+ $ expected = $ legacyExpected ?? $ expected ;
552+ }
553+
554+ $ this ->assertSame ($ expected , $ this ->createSanitizer ()->sanitizeFor ('table ' , $ input ));
555+ }
556+
557+ public static function provideSanitizeTable (): iterable
558+ {
559+ return [
560+ [
561+ '<caption>Lorem ipsum</caption> ' ,
562+ '<caption>Lorem ipsum</caption> ' ,
563+ ],
534564 [
535565 '<tbody>Lorem ipsum</tbody> ' ,
566+ '<tbody></tbody> ' ,
536567 '<tbody>Lorem ipsum</tbody> ' ,
537568 ],
538569 [
539570 '<td>Lorem ipsum</td> ' ,
571+ '<tbody><tr><td>Lorem ipsum</td></tr></tbody> ' ,
540572 '<td>Lorem ipsum</td> ' ,
541573 ],
542574 [
543575 '<tfoot>Lorem ipsum</tfoot> ' ,
576+ '<tfoot></tfoot> ' ,
544577 '<tfoot>Lorem ipsum</tfoot> ' ,
545578 ],
546579 [
547580 '<thead>Lorem ipsum</thead> ' ,
581+ '<thead></thead> ' ,
548582 '<thead>Lorem ipsum</thead> ' ,
549583 ],
550584 [
551585 '<th>Lorem ipsum</th> ' ,
586+ '<tbody><tr><th>Lorem ipsum</th></tr></tbody> ' ,
552587 '<th>Lorem ipsum</th> ' ,
553588 ],
554589 [
555590 '<tr>Lorem ipsum</tr> ' ,
591+ '<tbody><tr></tr></tbody> ' ,
556592 '<tr>Lorem ipsum</tr> ' ,
557593 ],
594+ ];
595+ }
596+
597+ #[DataProvider('provideSanitizeHtml ' )]
598+ public function testSanitizeHtml (string $ input , string $ expected )
599+ {
600+ $ this ->assertSame ($ expected , $ this ->createSanitizer ()->sanitizeFor ('html ' , $ input ));
601+ }
602+
603+ public static function provideSanitizeHtml (): iterable
604+ {
605+ return [
558606 [
559- '<ul>Lorem ipsum</ul > ' ,
560- '<ul>Lorem ipsum</ul > ' ,
607+ '<BODY BACKGROUND="javascript:alert( \' XSS \' )" > ' ,
608+ '<body></body > ' ,
561609 ],
562610 ];
563-
564- foreach ($ cases as $ case ) {
565- yield $ case [0 ] => $ case ;
566- }
567611 }
568612
569613 public function testUnlimitedLength ()
0 commit comments