|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-07-05 06:45 UTC] qdinar at gmail dot com
Description: ------------ cdata which was used to escape html tags inside strings inside script tags failed to perform that task while it was feed to PHP's DOMDocument's loadHTML , which is made with libxml. you can see in the example that "c='456'; //]]> " - content of script element is going to be outputted to user. i reported this for libxml to https://bugzilla.gnome.org/show_bug.cgi?id=784517 but it was suggested to report to php. i have found similar bug https://bugs.php.net/bug.php?id=71452 here but it is for case without "cdata", so i report another bug. Test script: --------------- $test_content=' <script> //<![CDATA[ a=\'123\'; b=\'</script>\'; c=\'456\'; //]]> </script> '; $d=new DOMDocument(); $d->loadHTML($test_content); echo $d->saveHTML(); Expected result: ---------------- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head> <script> //<![CDATA[ a='123'; b='</script>'; c='456'; //]]> </script> </head> <body></body> </html> Actual result: -------------- PHP Warning: DOMDocument::loadHTML(): Unexpected end tag : script in Entity, line: 8 in C:\xampp\htdocs\test\dom_cdata.php on line 13 Warning: DOMDocument::loadHTML(): Unexpected end tag : script in Entity, line: 8 in C:\xampp\htdocs\test\dom_cdata.php on line 13 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head><script> //<![CDATA[ a='123'; b='</script></head><body><p>'; c='456'; //]]> </p></body></html> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 05:00:01 2025 UTC |
requinix, i tried same script with this (instead of "echo $d->saveHTML();") : $es=$d->getElementsByTagName('script'); echo $es->item(0)->childNodes->item(0)->nodeType; and it outputted 4 which is: XML_CDATA_SECTION_NODE (integer) 4 Node is a DOMCharacterData - http://php.net/manual/en/dom.constants.php