Bug #74863 [Opn->Dup]: php DOMDocument loadHTML parses html tags inside comments

From: Date: Thu, 06 Jul 2017 09:04:32 +0000
Subject: Bug #74863 [Opn->Dup]: php DOMDocument loadHTML parses html tags inside comments
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209841@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74863&edit=1

 ID:                 74863
 Updated by:         requinix@php.net
 Reported by:        qdinar at gmail dot com
 Summary:            php DOMDocument loadHTML parses html tags inside
                     comments
-Status:             Open
+Status:             Duplicate
 Type:               Bug
 Package:            *General Issues
 Operating System:   windows 10
 PHP Version:        5.6.30
 Block user comment: N
 Private report:     N

 New Comment:

Read what I said in #71452.


Previous Comments:
------------------------------------------------------------------------
[2017-07-06 09:00:29] qdinar at gmail dot com

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';
// --&gt;
</p></body></html>



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74863&edit=1


Thread (3 messages)

« previous php.bugs (#209841) next »