Bug #74858 [NEW]: DOMDocument loadHTML parses html tags inside cdata
From: qdinar at gmail dot com
Operating system: windows 10
PHP version: 5.6.30
Package: *General Issues
Bug Type: Bug
Bug description:DOMDocument loadHTML parses html tags inside cdata
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>
--
Edit bug report at https://bugs.php.net/bug.php?id=74858&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74858&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74858&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74858&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74858&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74858&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74858&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74858&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74858&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74858&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74858&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74858&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74858&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74858&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74858&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74858&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74858&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74858&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74858&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74858&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74858&r=mysqlcfg
Thread (5 messages)
- qdinar at gmail dot com