From:             icewavestone at gmail dot com
Operating system: all
PHP version:      5.3.18
Package:          DOM XML related
Bug Type:         Bug
Bug 
description:dom处理标签script闭合时会将script标签里的数据丢失一部分

Description:
------------
使用DOMDocument对一段字符串进行标签闭合处理时,如果字符串包含有script标签,在<script></script>标签里的其他的标签会在进行标签闭合处理时,会出现丢失。如字符串:<b>aaaaa<div
         
ID="te<te"st>st">&nbsp;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">&nbsp;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 bug report at https://bugs.php.net/bug.php?id=63417&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63417&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63417&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63417&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63417&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63417&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63417&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63417&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63417&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63417&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63417&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63417&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63417&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63417&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63417&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63417&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63417&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63417&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63417&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63417&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63417&r=mysqlcfg

Reply via email to