#52 [Com]: XML_RPC processes data as UTF-8 regardless of actual encoding

From: Date: Sat, 11 Oct 2003 14:35:09 +0000
Subject: #52 [Com]: XML_RPC processes data as UTF-8 regardless of actual encoding
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-22600@lists.php.net to get a copy of this message
ID: 52 Comment by: mroch@php.net Reported By: daniel at ilse dot net Status: Open Bug Type: XML_RPC PHP Version: Irrelevant New Comment: This looks pretty good to me, except I'm wondering if there's a better way to get the first line (the XML declaration "<?xml...>" must be on the first line). Also, how can this be tested? Previous Comments: ------------------------------------------------------------------------ [2003-10-01 05:16:05] daniel at ilse dot net Description: ------------ The PEAR XMLRPC package handles xmldata as a UTF-8 stream, even if it's encoded otherwise. In my case data was being sent with encoding='ISO-8859-1' and containing valid 8bit characters, the result was an XMLRPC error 'invalid_return'. Fix: get the encoding from the actual xml data, something like this: (patch against $Id: RPC.php,v 1.11 2002/10/02 21:10:19 ssb Exp $) --- /usr/local/lib/php/XML/RPC.php.orig Tue Sep 30 15:17:25 2003 +++ /usr/local/lib/php/XML/RPC.php Tue Sep 30 15:20:31 2003 @@ -616,12 +616,46 @@ return $this->parseResponse($ipd); } + function getEncoding($str) + { + $rc=$GLOBALS['XML_RPC_defencoding']; + + $lines=preg_split('/(\r\n|\r|\n)/',$str); + + foreach($lines as $line) + { + if(preg_match('/<\?xml[^>]*\s*encoding\s*=\s*[\'"]([^"\']*)[\'"]/i',$line,$match)) + { + $rc=trim($match[1]); + + break; + } + } + + return $rc; + } + function parseResponse($data="") { global $XML_RPC_xh,$XML_RPC_err,$XML_RPC_str; global $XML_RPC_defencoding; - $parser = xml_parser_create($XML_RPC_defencoding); + if($data!="") + { + $encoding=$this->getEncoding($data); + } + else + { + $encoding=$XML_RPC_defencoding; + } + + $parser = xml_parser_create($encoding); $XML_RPC_xh[$parser]=array(); ------------------------------------------------------------------------ -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=52&edit=1

« previous php.pear.dev (#22600) next »