Bug #53628 [Opn->Bgs]: Lack of support for character references
| From: | rrichards@php.net | Date: | Wed, 29 Dec 2010 22:18:02 +0000 |
| Subject: | Bug #53628 [Opn->Bgs]: Lack of support for character references | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-157400@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53628&edit=1
ID: 53628
Updated by: rrichards@php.net
Reported by: alexander dot grimalovsky at gmail dot com
Summary: Lack of support for character references
-Status: Open
+Status: Bogus
Type: Bug
Package: DOM XML related
Operating System: All
PHP Version: 5.3.4
Block user comment: N
Private report: N
New Comment:
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
createEntityReference works per spec. It is only supposed to support
entity
references - not character references. You typically use a text node
with escaped
data to add characters.
Previous Comments:
------------------------------------------------------------------------
[2010-12-29 17:58:21] alexander dot grimalovsky at gmail dot com
Description:
------------
DOM extension for PHP supports XML entity references by implementing
DOMEntityReference class. However due to incorrect entity name
validation this class only allows working with named entity references,
not character references.
libxml2, which is used as backend implementation for DOM XML operations
have 2 functions for creating entity references:
xmlNewReference() - for entity references, it is used by DOM extension
xmlNewCharRef() - for character references, it is not used by DOM
extension and hence causes extension to lack support for this kind of
entities.
Moreover, implementation of DOMEntityReference::__construct() in
ext/dom/entityreference.c uses libxml2 function xmlValidateName() for
validating entity name which checks for Name (see
http://www.w3.org/TR/REC-xml/#NT-EntityRef).
Of course this check is
failed on character references ( see
http://www.w3.org/TR/REC-xml/#NT-CharRef) and
hence causes exception or
warning error to be thrown.
Correct implementation should check for "#" character at a first
position of given entity name and call xmlNewReference() or
xmlNewCharRef() depending on test result.
PHP 5.2.x is also affected by this problem.
Test script:
---------------
<?php
$xml = new DOMDocument('1.0','utf-8');
$node = $xml->createElement('test');
$xml->appendChild($node);
$named = $xml->createEntityReference('entity'); // Create named
entity, works
$node->appendChild($named);
$char = $xml->createEntityReference('#xAA'); // Create character
reference, doesn't work
$node->appendChild($char);
echo $xml->saveXML();
Expected result:
----------------
<?xml version="1.0" encoding="utf-8"?>
<test>&entity;ª</test>
Actual result:
--------------
Fatal error: Uncaught exception 'DOMException' with message 'Invalid
Character Error' in test.php:7
Stack trace:
#0 test.php(7): DOMDocument->createEntityReference('#xAA')
#1 {main}
thrown in test.php on line 7
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53628&edit=1