Bug #74863 [NEW]: php DOMDocument loadHTML parses html tags inside comments
From: qdinar at gmail dot com
Operating system: windows 10
PHP version: 5.6.30
Package: *General Issues
Bug Type: Bug
Bug description:php DOMDocument loadHTML parses html tags inside comments
Description:
------------
html comment boundary marks 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.
this is found by trying simple html comments after reading comments on
bug https://bugs.php.net/bug.php?id=74858 .
Test script:
---------------
$d=new DOMDocument();
$test_content='
<script>
//<!--
a=\'123\';
b=\'</script>\';
c=\'456\';
// -->
</script>
';
$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>
//<!--
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_load_html.php on line 38
Warning: DOMDocument::loadHTML(): Unexpected end tag : script in Entity,
line: 8 in C:\xampp\htdocs\test\dom_load_html.php on line 38
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><script>
//<!--
a='123';
b='</script></head><body><p>';
c='456';
// -->
</p></body></html>
--
Edit bug report at https://bugs.php.net/bug.php?id=74863&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74863&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74863&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74863&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74863&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74863&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74863&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74863&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74863&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74863&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74863&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74863&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74863&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74863&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74863&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74863&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74863&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74863&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74863&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74863&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74863&r=mysqlcfg
Thread (3 messages)
- qdinar at gmail dot com