#33020 [Opn->Bgs]: getAttribute() incorrectly de-references entities
| From: | chregu@php.net | Date: | Fri, 13 May 2005 06:53:56 +0000 |
| Subject: | #33020 [Opn->Bgs]: getAttribute() incorrectly de-references entities | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-78965@lists.php.net to get a copy of this message | ||
ID: 33020
Updated by: chregu@php.net
Reported By: mark at kimsal dot com
-Status: Open
+Status: Bogus
Bug Type: DOM XML related
Operating System: Linux
PHP Version: 5.0.4
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
It's UTF-8 encoded, but you output is as ISO-8859-1 (same goes for
htmlentities).
(Almost) anything from DOM is UTF-8 encoded.
Previous Comments:
------------------------------------------------------------------------
[2005-05-12 21:53:59] mark at kimsal dot com
Description:
------------
When using getAttribute to get the value of an attribute
that contains an XML entity (eg. ®) the returned value
is neither the actual character that is being represented
nor the characters that make up the entity '&' '#' '1'
'7'
'4'. Instead there are two characters that are returned, A
circumflex (Ã) and, in this example, the registered
trademark symbol (®).
'./configure' '--prefix=/opt/php5' '--with-mysql'
'--with-apxs2=/usr/sbin/apxs2' '--with-zlib' '--with-expat'
'--enable-sigchild' '--with-openssl' '--enable-shared'
'--enable-soap' '--with-gd' '--enable-mbstring'
'--with-pgsql' '--with-imap=shared,/usr/lib'
'--with-imap-ssl=no' '--with-gd'
'--with-jpeg-dir=/usr/include' '--with-ldap' '--with-xsl'
'--enable-memory-limit' '--enable-debug'
'--with-libxml-dir=/usr'
Reproduce code:
---------------
ent.php:
$dom = new DomDocument();
$dom->substituteEntities = true;
$dom->resolveExternals = true;
$dom->load('ent.xml');
$dom->substituteEntities = true;
$dom->resolveExternals = true;
echo $dom->saveXml();
$list = $dom->getElementsByTagName('bar');
$node = $list->item(0);
echo "\n===\n Attribute 'test' of node 'bar': ";
echo $node->getAttribute("test");
echo "\n===\n Attribute 'test' of node 'bar' with htmlentities:
";
echo htmlentities($node->getAttribute("test"));
echo "\n===\n";
ent.xml:
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY reg "®">
]>
<foo>
<bar test="®">®</bar>
</foo>
Expected result:
----------------
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY reg "®">
]>
<foo>
<bar test="®">®</bar>
</foo>
===
Attribute 'test' of node 'bar': ®
===
Attribute 'test' of node 'bar' with htmlentities:
&#174;
===
Actual result:
--------------
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY reg "®">
]>
<foo>
<bar test="®">®</bar>
</foo>
===
Attribute 'test' of node 'bar': ®
===
Attribute 'test' of node 'bar' with htmlentities:
®
===
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33020&edit=1