PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_Tree » Bug #2029

encodeXml / decodeXmlEntities not reciprocals

Details

Submitted2004-07-31 00:01 UTC
Fromcollectours at free dot fr
StatusSuspended
PackageXML_Tree
PHP Version4.3.8
OSLinux
Roadmaps(Not assigned)

Comments

[2004-07-31 00:01 UTC] collectours at free dot fr

Description:
------------
XML_Tree
Node.php,v 1.22 2004/05/26 15:03:25

A string passed through
XML_Tree_Node::encodeXmlEntities,
and then through
XML_Tree_Node::decodeXmlEntities is not anymore like the original
1 - the single quotes ' remains as entity apos;
2 - the ^ remains as #94
(ampersand and semicolon intentionnaly ommited in the report)

Reproduce code:
---------------
<?php
require_once('XML/Tree/Node.php');
$str = "bla ' bla^";
$encoded = XML_Tree_Node::encodeXmlEntities($str);
$decoded = XML_Tree_Node::decodeXmlEntities($encoded);
header('Content-type:text/plain');
print "before:$str\n";
print "after: $decoded\n";
?>

Expected result:
----------------
Should be
before:bla ' bla^
after: bla ' bla^
----------------------
1) The get_html_translation_table(HTML_ENTITIES) (with or without ENT_QUOTES) renders the single quote as #39, not apos; so it is not translated back
2) the \^ is missing in the preg_replace line 538

Actual result:
--------------
before:bla ' bla^
after: bla &apos; bla^

Fix proposal (tested):
1) in encodeXmlEntities
line 538 ...\+\,\@_\^])/e"

2) in decodeXmlEntities
$trans_tbl = array_flip($trans_tbl);
// add the apos not given by trans table
$trans_tbl['&apos;'] = "'";