php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37957 Timeout when setting nodeValue if entity in existing value
Submitted: 2006-06-29 06:16 UTC Modified: 2006-07-06 20:18 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jfowlie at navarik dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jfowlie at navarik dot com
New email:
PHP Version: OS:

 

 [2006-06-29 06:16 UTC] jfowlie at navarik dot com
Description:
------------
I was attempting to update the content of some anchor elements by setting the nodeValue. It doesn't seem to matter how high I set the max_execution_time limit, if there is a   entity in the nodeValue, PHP just hangs until it times out. (It works just fine with & though...)


Reproduce code:
---------------
<?php
$xhtml = <<<XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<a href="#" id="id-goes-here">Link 1</a>
<a href="#" id="id-2-goes-here">Link 2 &amp;</a>
<a href="#" id="id-3-goes-here">Link 3 &nbsp;</a>
</body>
</html>
XHTML;


$dom = new DOMDocument('1.0','iso-8859-1');

// I tried it with this set to true or false
//$xml->preserveWhiteSpace = FALSE;

// You need this, otherwise the nbsp entity is not valid
$dom->resolveExternals = TRUE;

$dom->loadXML($xhtml);

$bookmarks = $dom->getElementsByTagName('a');

$count = 0;

foreach($bookmarks as $bookmark_node){
        ++$count;
        $id_value = $bookmark_node->getAttribute('id');
        print "Id value: ".$id_value."<br />";
        print "Node value: ".$bookmark_node->nodeValue."<br />";
        print "Setting nodeValue to 'test$count'<br />";
        $bookmark_node->nodeValue = 'test'.$count;
        print "Node value has been set! ({$bookmark_node->nodeValue})<hr />";
}
?>


Expected result:
----------------
Id value: id-goes-here
Node value: Link 1
Setting nodeValue to 'test1'
Node value has been set! (test1)

Id value: id-2-goes-here
Node value: Link 2 &
Setting nodeValue to 'test2'
Node value has been set! (test2)

Id value: id-3-goes-here
Node value: Link 3
Setting nodeValue to 'test3'
Node value has been set! (test3)


Actual result:
--------------
Id value: id-goes-here
Node value: Link 1
Setting nodeValue to 'test1'
Node value has been set! (test1)

Id value: id-2-goes-here
Node value: Link 2 &
Setting nodeValue to 'test2'
Node value has been set! (test2)

Id value: id-3-goes-here
Node value: Link 3
Setting nodeValue to 'test3'

Fatal error: Maximum execution time of 30 seconds exceeded in nbsp-dom-test.php on line 39


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-29 08:19 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Can't reproduce.
 [2006-07-06 19:32 UTC] jfowlie at navarik dot com
Thanks. The CVS snapshot for v5.2 has fixed the issue.

Any word on when this version will become the official release? i.e. production ready? 

I can't use a development version of php on our production servers...

Cheers
 [2006-07-06 19:42 UTC] tony2001@php.net
It'll be ready when it's ready.
 [2006-07-06 20:18 UTC] jfowlie at navarik dot com
In case anyone wants a workaround...

Check that a node hasChildNodes and that the firstChild->nodeType is XML_TEXT_NODE. Then you can just set the value of the node with firstChild->nodeValue

I.e. change the foreach loop in the reproduce code to:

foreach($bookmarks as $bookmark_node){
        ++$count;
        $id_value = $bookmark_node->getAttribute('id');
        print "Id value: ".$id_value."<br />\n";
	if ($bookmark_node->hasChildNodes() && $bookmark_node->firstChild->nodeType == XML_TEXT_NODE) {
		print "Node value: ".$bookmark_node->firstChild->nodeValue."<br />\n";
		print "Setting nodeValue to 'test$count'<br />\n";
		$bookmark_node->firstChild->nodeValue = 'test'.$count;
		print "Node value has been set! ({$bookmark_node->firstChild->nodeValue})<hr />\n";
	}
}
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 01:01:33 2025 UTC