Home » XML » XML_Serializer » Bug #5187
Unserialize decodeFunction
Details
| Submitted | 2005-08-23 17:14 UTC |
|---|---|
| From | zik at zik dot hu |
| Assigned | schst |
| Status | Closed |
| Package | XML_Serializer |
| PHP Version | 5.0.4 |
| OS | Debian Sarge |
| Roadmaps | (Not assigned) |
Comments
[2005-08-23 17:14 UTC] zik at zik dot hu
Description:
------------
I think the decodeFunction option is not handled properly.
At least I could not use it to work around missing target encodings of xml parser. (By having a small function that calls iconv() on input set as decodeFunction.)
http://www.php.net/manual/en/function.xml-parser-set-option.php
"Supported target encodings are ISO-8859-1, US-ASCII and UTF-8."
Applying the attached patch solves this problem.
NOTES: I don't know if this decodeFunction was intended for this or not, but this is how I need it. :)
I also don't understand why the tag name is decoded and the value of attributes, but not the name of attributes.
I don't believe attribute or tag names should be decoded. At least not for encoding conversion purposes. (It's not advisable to have xml tag and attr names in any other encoding than us-ascii, imho.)
But if tag names are decoded then attribute names should be decoded as well.
Test script:
---------------
Unserializer-0.16.0_decode.patch:
--- Unserializer.php.orig 2005-08-23 12:30:35.000000000 +0200
+++ Unserializer.php 2005-08-23 18:22:51.000000000 +0200
@@ -366,11 +366,12 @@
} else {
$type = 'string';
}
if ($this->options['decodeFunction'] !== null) {
- $element = call_user_func($this->options['decodeFunction'], $element);
+ /* Do not decode element name */
+ /* $element = call_user_func($this->options['decodeFunction'], $element); */
$attribs = array_map($this->options['decodeFunction'], $attribs);
}
$this->_depth++;
$this->_dataStack[$this->_depth] = null;
@@ -552,10 +553,15 @@
* @param string CDATA
* @return void
*/
function cdataHandler($parser, $cdata)
{
+ if ($this->options['decodeFunction'] !== null) {
+ /* Decode character data */
+ $cdata = call_user_func( $this->options['decodeFunction'], $cdata );
+ }
+
$this->_dataStack[$this->_depth] .= $cdata;
}
/**
* create the XML_Parser instance