php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38354 Unwanted reformatting of XML when using AsXML
Submitted: 2006-08-06 08:47 UTC Modified: 2006-08-06 19:40 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rowanjl at gmail dot com Assigned:
Status: Closed Package: SimpleXML related
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
 [2006-08-06 08:47 UTC] rowanjl at gmail dot com
Description:
------------
When using AsXML on an element which contains children, the returned source is different from the original XML source. This prevents any direct comparison between the two.

Reproduce code:
---------------
<?php
	
	Header("Content-type: text/plain");
	
	$XML = SimpleXML_Load_String('<code>
	<a href="javascript:alert(\'1\');"><strong>Item Two</strong></a>
</code>');
	
	foreach ($XML->XPath("//*") as $Element) {
		echo Trim($Element->AsXML()), "\n--------------------\n";
	}
	
?>

Expected result:
----------------
<?xml version="1.0"?>
<code>
	<a href="javascript:alert('1');"><strong>Item Two</strong></a>
</code>
--------------------
<a href="javascript:alert('1');">
  <strong>Item Two</strong>
</a>
--------------------
<strong>Item Two</strong>
--------------------

Actual result:
--------------
<?xml version="1.0"?>
<code>
	<a href="javascript:alert('1');"><strong>Item Two</strong></a>
</code>
--------------------
<a href="javascript:alert('1');"><strong>Item Two</strong></a>
--------------------
<strong>Item Two</strong>
--------------------

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-06 11:39 UTC] rowanjl at gmail dot com
The expected and actual results are reversed, I'd correct that if I could, sorry for the mix up.
 [2006-08-06 19:40 UTC] chregu@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in HEAD and PHP_5_2 branch
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC