MDL-76412 lib: Fixed PHP 8.2 utf8_encode deprecations in phpxmlrpc

This commit is contained in:
raortegar 2023-01-31 15:23:38 +01:00
parent 87f235e0bb
commit f6608a7e32
5 changed files with 18 additions and 24 deletions

View File

@ -303,17 +303,13 @@ 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);
} else {
if (extension_loaded('mbstring')) {
if (function_exists('mb_convert_encoding')) {
$xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding);
} else {
$this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding);
}
}
}
}
// 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'))) {

View File

@ -235,7 +235,9 @@ class Charset
case 'ISO-8859-1_UTF-8':
$escapedData = str_replace(array('&', '"', "'", '<', '>'), array('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $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('&amp;', '&quot;', '&apos;', '&lt;', '&gt;'), $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');

View File

@ -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);
} else {
if (extension_loaded('mbstring')) {
if (function_exists('mb_convert_encoding')) {
$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);
}
}
}

View File

@ -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);
} else {
if (extension_loaded('mbstring')) {
if (function_exists('mb_convert_encoding')) {
$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);
}
}
}

View File

@ -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.