php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30530 DOMCharacterData extending bug
Submitted: 2004-10-22 12:19 UTC Modified: 2004-10-22 14:43 UTC
From: jason at amp-design dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.0.1 OS: MacOS X / Win 2003 / CentOS
Private report: No CVE-ID: None
 [2004-10-22 12:19 UTC] jason at amp-design dot net
Description:
------------
In my example code class RawStuff extends DOMCharacterData and creates a fetch error, which I can't see why it's happening (nothing in the PHP manual or DOM specs seems to say anything as far as I can see).

If I change the code to 

class RawStuff extends DOMText

then the code doesn't error, however I don't want it to escape the < and > characters, which is why I want to extend from DOMCharacterData as this shouldn't escape < and > (coz it doesn't in DOMComment and that extends DOMCharacterData).

As far as I can see this seems to be a bug though, there maybe some good reason why this doesn't work, however there seems to be no mentioning of it in both the DOM Spec of PHP manual.

Reproduce code:
---------------
<?php

header('Content-type: text/plain');

class RawStuff extends DOMCharacterData {
	public $poop;
}

class NiceElement extends DOMElement {
}

$o = new DOMDocument();

// Expecting <scum /> to be escaped here with &gt; and &lt;
$p = new NiceElement('html', ' ppp<scum /> pp', '12121212'); 
$o->appendChild($p);

// Not expecting <% and %> to be escaped as DOMComment extends the DOMCharacterData class
// and this allows things like <!-- <scum /> --> without turning < and > into entites
// However we can't use DOMCharacterData directly without a fetch error for some reason
$cack = &new RawStuff('blah some node which can also hold raw <% asp data %>');   
$p->appendChild($cack);

$cack2 = $o->createTextNode('fgfgf');
$p->appendChild($cack2);
echo $o->saveXML();

?>

Expected result:
----------------
<?xml version="1.0"?>
<html xmlns="12121212"> ppp&lt;scum /&gt; ppblah some node which can also hold raw <% asp data %>fgfgf</html>

Actual result:
--------------
<br />
<b>Warning</b>:  Couldn't fetch RawStuff in <b>/data/web/test_stuff/DOM_test.php</b> on line <b>22</b><br />
<?xml version="1.0"?>
<html xmlns="12121212"> ppp&lt;scum /&gt; ppfgfgf</html>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-22 13:41 UTC] Jason at amp-design dot net
Just out of interest, would this be to do with the fact there is no XML Constant related to DOMCharacterData nodes, where as other nodes do (e.g. DOMElement will have a node type of XML_ELEMENT_NODE).
 [2004-10-22 14:43 UTC] chregu@php.net
What you're trying to do, doesn't work for several reasons...

you can't use new DomCharacterData() to append it to a document. you have to use $dom->createTextNode(), for example..

Second, what you want, would produce invalid XML anyway, use 
$dom->createCdataSection(), maybe that works for your case.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC