X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fxmlrpcs.inc;h=6dd64a51fef3bcb4f2d9562c6ba7f619bfc98543;hb=f45909a92b268970729c121269af62d71eb7cd47;hp=180595c7a99d21c91ee6a38e75f4a4149c8b161b;hpb=3d1bcf262c3d7467b5e94cac3c0e3fd3c0563eeb;p=plcapi.git diff --git a/lib/xmlrpcs.inc b/lib/xmlrpcs.inc index 180595c..6dd64a5 100644 --- a/lib/xmlrpcs.inc +++ b/lib/xmlrpcs.inc @@ -928,26 +928,28 @@ $GLOBALS['_xh']['rt']=''; // decompose incoming XML into request structure + if ($req_encoding != '') { - if (!in_array($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) - // the following code might be better for mb_string enabled installs, but - // makes the lib about 200% slower... - //if (!is_valid_charset($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) - { - error_log('XML-RPC: '.__METHOD__.': invalid charset encoding of received request: '.$req_encoding); - $req_encoding = $GLOBALS['xmlrpc_defencoding']; - } - /// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue, - // the encoding is not UTF8 and there are non-ascii chars in the text... - /// @todo use an empty string for php 5 ??? - $parser = xml_parser_create($req_encoding); - } - else - { - $parser = xml_parser_create(); + // Since parsing will fail if charset is not specified in the xml prologue, + // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that... + // The following code might be better for mb_string enabled installs, but + // makes the lib about 200% slower... + //if (!is_valid_charset($req_encoding, array('UTF-8'))) + if (!in_array($req_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) { + if ($req_encoding == 'ISO-8859-1') { + $data = utf8_encode($data); + } else { + if (extension_loaded('mbstring')) { + $data = mb_convert_encoding($data, 'UTF-8', $req_encoding); + } else { + error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding); + } + } + } } + $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell // the xml parser to give us back data in the expected charset