33
44use Masterminds \HTML5 \Serializer \OutputRules ;
55use Masterminds \HTML5 \Serializer \Traverser ;
6+ use Masterminds \HTML5 ;
67
78class OutputRulesTest extends \Masterminds \HTML5 \Tests \TestCase
89{
@@ -18,6 +19,11 @@ class OutputRulesTest extends \Masterminds\HTML5\Tests\TestCase
1819 </body>
1920 </html> ' ;
2021
22+ /**
23+ * @var HTML5
24+ */
25+ protected $ html5 ;
26+
2127 public function setUp ()
2228 {
2329 $ this ->html5 = $ this ->getInstance ();
@@ -29,7 +35,7 @@ public function setUp()
2935 * @param string $name
3036 * The name of the method on the Traverser class to test.
3137 *
32- * @return \ReflectionMethod \ReflectionMethod for the specified method
38+ * @return \ReflectionMethod for the specified method
3339 */
3440 public function getProtectedMethod ($ name )
3541 {
@@ -613,4 +619,32 @@ public function testAddressTag()
613619 $ this ->assertRegExp ('|contact persons for the <a href="Activity">W3C HTML Activity</a>| ' , $ contents );
614620 $ this ->assertRegExp ('|</address>| ' , $ contents );
615621 }
622+
623+ /**
624+ * Ensure direct DOM manipulation doesn't break TEXT_RAW elements (iframe, script, etc...)
625+ */
626+ public function testHandlingInvalidRawContent ()
627+ {
628+ $ dom = $ this ->html5 ->loadHTML (
629+ '<!doctype html>
630+ <html lang="en" id="base">
631+ <body>
632+ <script id="template" type="x-tmpl-mustache">
633+ <h1>Hello!</h1>
634+ </script>
635+ </body>
636+ </html> ' );
637+
638+ $ badNode = $ dom ->createElement ("p " , "Bar " );
639+
640+ // modify the content of the TEXT_RAW element: <script id="template"> appending dom nodes
641+ $ styleElement = $ dom ->getElementById ("template " );
642+ $ styleElement ->appendChild ($ badNode );
643+
644+ $ contents = $ this ->html5 ->saveHTML ($ dom );
645+
646+ $ this ->assertTrue (strpos ($ contents , '<script id="template" type="x-tmpl-mustache">
647+ <h1>Hello!</h1>
648+ <p>Bar</p></script> ' )!==false );
649+ }
616650}
0 commit comments