Skip to content

Commit

Permalink
improve xmlrpc_decode; bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Apr 14, 2024
1 parent 7760c5d commit f2bd51f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
## vXXX (unreleased)

- Improved: moved CI testing from Travis to GitHub Actions. Added testing on php 8.1 and 8.2. Default the local testing
container to using PHP 7.4 on Ubuntu Focal
- Improved: fixed many corner cases for function `xmlrpc_decode`

- Improved: moved CI testing from Travis to GitHub Actions. Added testing on php 8.1, 8.2 and 8.3. Default the local
testing container to using PHP 7.4 on Ubuntu Focal

- Changed: bumped requirements to php 5.4, phpxmlrpc 4.10


## v1.0-RC1 (2022/1/30)

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"ext-xmlrpc": "*"
},
"require": {
"php": "^5.3.0 || ^7.0 || ^8.0",
"phpxmlrpc/phpxmlrpc": "^4.5.2"
"php": "^5.4.0 || ^7.0 || ^8.0",
"phpxmlrpc/phpxmlrpc": "^4.10.0"
},
"require-dev": {
"ext-curl": "*",
Expand Down
19 changes: 12 additions & 7 deletions src/XmlRpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,22 @@ final class XmlRpc
* characters which can not be represented in the target encoding, the returned data will
* be in utf8
* @return mixed
* @bug known case not to work atm: '<params><param><value><string>Hello</string></value></param><param><value><string>Dolly</string></value></param></params>'
*/
public static function xmlrpc_decode($xml, $encoding = "iso-8859-1")
{
$encoder = new Encoder();
if (strpos($xml, '<methodResponse>') === false
&& strpos($xml, '<methodCall>') === false
) {
// strip out unnecessary xml in case we're deserializing a single param.
// in case of a complete response, we do not have to strip anything
// please note that the test below has LARGE space for improvement (eg. it might trip on xml comments...)
// Strip out unnecessary xml in case we're deserializing a single param.
// In case of a complete response, we do not have to strip anything.
// Please note that the test below has LARGE space for improvement (eg. it does not work for an xml chunk
// with 2 or more params. Also, it might trip on xml comments...)
$xmlDeclRegex = '<\?xml\s+version\s*=\s*["\']1\.[0-9]+["\'](?:\s+encoding=["\'][A-Za-z](?:[A-Za-z0-9._]|-)*["\'])?\s*\?>';
if (preg_match('/^(' . $xmlDeclRegex . ')?\s*<params>/', $xml)) {
$xml = preg_replace(array('!\s*<params>\s*<param>\s*!', '!\s*</param>\s*</params>\s*$!'), array('', ''), $xml);
} elseif (preg_match('/^(' . $xmlDeclRegex . ')?\s*<param>/', $xml)) {
$xml = preg_replace(array('!\s*<param>\s*!', '!\s*</param>\s*$!'), array('', ''), $xml);
} elseif (preg_match('#^(' . $xmlDeclRegex . ')?\s*(<(?:int|i4|boolean|string|double|dateTime.iso8601|struct|array)>.+</(?:int|i4|boolean|string|double|dateTime.iso8601|struct|array)>)$#', $xml, $matches)) {
$xml = $matches[1] . '<value>' . $matches[2] . '</value>';
}

$defaultEncoding = PhpXmlRpc::$xmlrpc_internalencoding;
Expand Down Expand Up @@ -461,7 +466,7 @@ public static function xmlrpc_server_register_introspection_callback($server, $f
public static function xmlrpc_server_register_method($server, $method_name, $function)
{
if ($server instanceof BaseServer) {
$server->add_to_map($method_name, $function);
$server->addToMap($method_name, $function);
return true;
}
return false;
Expand Down

0 comments on commit f2bd51f

Please sign in to comment.