allow flexible charset decoding for polyfill-xmlrpc
authorgggeek <giunta.gaetano@gmail.com>
Sat, 9 Jan 2021 18:34:31 +0000 (18:34 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 9 Jan 2021 18:34:31 +0000 (18:34 +0000)
NEWS
src/Encoder.php

diff --git a/NEWS b/NEWS
index f3caf81..0ff0d6d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-XML-RPC for PHP version 4.5.2 - unreleased
+XML-RPC for PHP version 4.5.2 - 2021/1/9
 
 * improved: better phpdocs in the the php code generated by the Wrapper class
 
@@ -6,6 +6,8 @@ XML-RPC for PHP version 4.5.2 - unreleased
 
 * improved: debugger favicon and page title when used from the phpjsonrpc library
 
+* fixed: allow `Encoder::decode` to properly support different target character sets for polyfill-xmlrpc decode functions
+
 
 XML-RPC for PHP version 4.5.1 - 2021/1/3
 
index d352831..ecb64bd 100644 (file)
@@ -54,8 +54,17 @@ class Encoder
                                 'scalar' => $val
                             );
                             return (object)$xmlrpcVal;
+                        case 'string':
+                            if (isset($options['extension_api_encoding'])) {
+                                $dval = @iconv('UTF-8', $options['extension_api_encoding'], $val);
+                                if ($dval !== false) {
+                                    return $dval;
+                                }
+                            }
+                            //return $val;
+                            // break through voluntarily
                         default:
-                            return $xmlrpcVal->scalarval();
+                            return $val;
                     }
                 }
                 if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalartyp() == 'dateTime.iso8601') {
@@ -279,6 +288,7 @@ class Encoder
 
         // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8!
         if (!in_array(PhpXmlRpc::$xmlrpc_internalencoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) {
+            /// @todo emit a warning
             $parserOptions = array(XML_OPTION_TARGET_ENCODING => 'UTF-8');
         } else {
             $parserOptions = array(XML_OPTION_TARGET_ENCODING => PhpXmlRpc::$xmlrpc_internalencoding);