diff --git a/lib/phpxmlrpc/Encoder.php b/lib/phpxmlrpc/Encoder.php index 7ad2adb06d0..2bee668b4fb 100644 --- a/lib/phpxmlrpc/Encoder.php +++ b/lib/phpxmlrpc/Encoder.php @@ -303,14 +303,10 @@ class Encoder // The following code might be better for mb_string enabled installs, but makes the lib about 200% slower... //if (!is_valid_charset($valEncoding, array('UTF-8')) if (!in_array($valEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($xmlVal)) { - if ($valEncoding == 'ISO-8859-1') { - $xmlVal = utf8_encode($xmlVal); + if (function_exists('mb_convert_encoding')) { + $xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding); } else { - if (extension_loaded('mbstring')) { - $xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding); - } else { - $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding); - } + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding); } } } diff --git a/lib/phpxmlrpc/Helper/Charset.php b/lib/phpxmlrpc/Helper/Charset.php index 5fa54225a36..fd7cf9eaf48 100644 --- a/lib/phpxmlrpc/Helper/Charset.php +++ b/lib/phpxmlrpc/Helper/Charset.php @@ -235,7 +235,9 @@ class Charset case 'ISO-8859-1_UTF-8': $escapedData = str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $data); - $escapedData = utf8_encode($escapedData); + if (function_exists('mb_convert_encoding')) { + $escapedData = mb_convert_encoding($escapedData, 'UTF-8', 'ISO-8859-1'); + } break; case 'ISO-8859-1_US-ASCII': @@ -256,7 +258,7 @@ class Charset $escapedData = str_replace(array('&', '"', "'", '<', '>'), array('&', '"', ''', '<', '>'), $data); /// @todo we could use real UTF8 chars here instead of xml entities... (note that utf_8 encode all alone will NOT convert them) $escapedData = str_replace($this->xml_cp1252_Entities['in'], $this->xml_cp1252_Entities['out'], $escapedData); - $escapedData = utf8_encode($escapedData); + $escapedData = mb_convert_encoding($escapedData, 'UTF-8', 'ISO-8859-1'); break; case 'CP1252_ISO-8859-1': $this->buildConversionTable('xml_cp1252_Entities'); diff --git a/lib/phpxmlrpc/Request.php b/lib/phpxmlrpc/Request.php index 9841c015031..0e4d1b87b80 100644 --- a/lib/phpxmlrpc/Request.php +++ b/lib/phpxmlrpc/Request.php @@ -304,15 +304,10 @@ class Request // The following code might be better for mb_string enabled installs, but makes the lib about 200% slower... //if (!is_valid_charset($respEncoding, array('UTF-8'))) if (!in_array($respEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) { - if ($respEncoding == 'ISO-8859-1') { - $data = utf8_encode($data); + if (function_exists('mb_convert_encoding')) { + $data = mb_convert_encoding($data, 'UTF-8', $respEncoding); } else { - - if (extension_loaded('mbstring')) { - $data = mb_convert_encoding($data, 'UTF-8', $respEncoding); - } else { - $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received response: ' . $respEncoding); - } + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': unsupported charset encoding of received response: ' . $respEncoding); } } } diff --git a/lib/phpxmlrpc/Server.php b/lib/phpxmlrpc/Server.php index 1cc965f3d32..40847569e9f 100644 --- a/lib/phpxmlrpc/Server.php +++ b/lib/phpxmlrpc/Server.php @@ -558,14 +558,10 @@ class Server // makes the lib about 200% slower... //if (!is_valid_charset($reqEncoding, array('UTF-8'))) if (!in_array($reqEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) { - if ($reqEncoding == 'ISO-8859-1') { - $data = utf8_encode($data); + if (function_exists('mb_convert_encoding')) { + $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding); } else { - if (extension_loaded('mbstring')) { - $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding); - } else { - $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding); - } + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': unsupported charset encoding of received request: ' . $reqEncoding); } } } diff --git a/lib/phpxmlrpc/readme_moodle.txt b/lib/phpxmlrpc/readme_moodle.txt index ae13fbaaebe..326c3d6b768 100644 --- a/lib/phpxmlrpc/readme_moodle.txt +++ b/lib/phpxmlrpc/readme_moodle.txt @@ -20,3 +20,8 @@ Current version imported: 4.8.1 (c74cc31) Local changes: * readme_moodle.txt - this file ;-) + + * 2023-01-31 lib/phpxmlrpc/* has minor changes for PHP 8.2 compatibility. See MDL-76412 for more details. + Since version 4.9.5, phpxmlrpc already has the fix, so if someone executing the upgrading version and + it has the patch, please ignore this note. + * 2023-01-31 Applied patch https://github.com/gggeek/phpxmlrpc/pull/110. See MDL-76412 for more details. \ No newline at end of file