Bug #63417 [Com]: html tags between <script> lost while parsed by dom
| From: | icewavestone at gmail dot com | Date: | Mon, 05 Nov 2012 09:47:40 +0000 |
| Subject: | Bug #63417 [Com]: html tags between <script> lost while parsed by dom | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174526@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63417&edit=1
ID: 63417
Comment by: icewavestone at gmail dot com
Reported by: icewavestone at gmail dot com
Summary: html tags between <script> lost while parsed by dom
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: all
PHP Version: 5.3.18
Block user comment: N
Private report: N
New Comment:
好å§ï¼è¿ä¸æ¯phpçBUGï¼æ¯libxmlçã
Previous Comments:
------------------------------------------------------------------------
[2012-11-02 08:00:38] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
ä½ ä½¿ç¨äºlibxml_use_internal_errorséé»äºé误æç¤º.
å®é
ä¸PHPå·²ç»åè¯äºä½ :
PHP Warning: DOMDocument::loadHTML(): Unexpected end tag : span in Entity
//
I'd like to mark this as a Nab, since PHP will warning you about the abnormal
html
like:
PHP Warning: DOMDocument::loadHTML(): Unexpected end tag : span in Entity
but you used libxml_use_internal_errors to suppress it.
thanks
------------------------------------------------------------------------
[2012-11-02 07:27:44] icewavestone at gmail dot com
Description:
------------
使ç¨DOMDocument坹䏿®µå符串è¿è¡æ ç¾éåå¤çæ¶ï¼å¦æå符串å
嫿scriptæ ç¾ï¼å¨<script></script>æ ç¾éçå
¶ä»çæ ç¾ä¼å¨è¿è¡æ ç¾éåå¤çæ¶ï¼ä¼åºç°ä¸¢å¤±ãå¦å符串ï¼<b>aaaaa<div
ID="te<te"st>st"> startstartstartenhao好å¼å§æµ<b>è¯ç¼è¾å¨\næäº¤çæ°æ®<br>åµ\nåµ<br>åå<br>å¯endendendend\n\n<br></div><script><span>111</span>alert("<span>ä½ å¥½ï¼</span>")</script>ã
å
¶ä¸<script><span>111</span>alert("<span>ä½ å¥½ï¼</span>")</script>è¿æ®µå符串ä¼å¨ç»è¿ï¼
$dom = new DOMDocument();
$dom->loadHTML('<html><head><meta http-equiv="Content-Type"
content="text/html; charset=utf-8"></head><body>' . $html .
'</body></html>');
$html = $dom->saveHTML();
è¿äºå½æ°å¤çåï¼åæï¼
<script><span>111alert("<span>ä½ å¥½ï¼")</script>
ä¸ç¥ä¸ºä»ä¹ä¼æ¯è¿æ ·çç»æ
Test script:
---------------
宿´çæµè¯ä»£ç 段为ï¼
$html = '<b>aaaaa<div
ID="te<te"st>st"> startstartstartenhao好å¼å§æµ<b>è¯ç¼è¾å¨\næäº¤çæ°æ®<br>åµ\nåµ<br>åå<br>å¯endendendend\n\n<br></div><script><span>111</span>alert("<span>ä½ å¥½ï¼</span>")</script>';
libxml_clear_errors();
$libxml_use_errors = libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML('<html><head><meta http-equiv="Content-Type"
content="text/html; charset=utf-8"></head><body>' . $html .
'</body></html>');
$html = $dom->saveHTML();
$body_start = strpos($html, '<body>');
$body_end = strrpos($html, '</body>');
$new_string = str_replace("\n", '', substr($html, $body_start + 6, $body_end -
$body_start - 6));
libxml_use_internal_errors($libxml_use_errors);
echo $html . "\n" . $new_string . "\n";
Expected result:
----------------
æµè¯å符串ï¼
<script><span>111</span>alert("<span>ä½ å¥½ï¼</span>")</script>
ç»è¿:$dom = new DOMDocument();
$dom->loadHTML('<html><head><meta http-equiv="Content-Type"
content="text/html; charset=utf-8"></head><body>' . $html .
'</body></html>');
$html = $dom->saveHTML();å¤çåï¼
叿è¿åºè¯¥æ¯ï¼
<script><span>111</span>alert("<span>ä½ å¥½ï¼</span>")</script>
Actual result:
--------------
å¦å符串ï¼
<script><span>111</span>alert("<span>ä½ å¥½ï¼</span>")</script>
ç°å¨çè¿åç»ææ¯ï¼
<script><span>111alert("<span>ä½ å¥½ï¼")</script>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63417&edit=1