From:             
Operating system: All
PHP version:      5.3.4
Package:          DOM XML related
Bug Type:         Bug
Bug description:Lack of support for character references

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;&#xAA;</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 bug report at http://bugs.php.net/bug.php?id=53628&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53628&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53628&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53628&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53628&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53628&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53628&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53628&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53628&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53628&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53628&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53628&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53628&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53628&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53628&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53628&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53628&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53628&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53628&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53628&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53628&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53628&r=mysqlcfg

Reply via email to