Explorar o código

Zend_XmlRpc_Value now correctly handles string as default

And it now passes test.
Tomas Paladin Volf %!s(int64=12) %!d(string=hai) anos
pai
achega
35334e3bc9
Modificáronse 2 ficheiros con 18 adicións e 1 borrados
  1. 3 1
      library/Zend/XmlRpc/Value.php
  2. 15 0
      tests/Zend/XmlRpc/ValueTest.php

+ 3 - 1
library/Zend/XmlRpc/Value.php

@@ -508,7 +508,9 @@ abstract class Zend_XmlRpc_Value
         // If no type was specified, the default is string
         // If no type was specified, the default is string
         if (!$type) {
         if (!$type) {
             $type = self::XMLRPC_TYPE_STRING;
             $type = self::XMLRPC_TYPE_STRING;
-            $value = str_replace(array('<value>', '</value>'), '', $xml->asXML());
+            if (preg_match('#^<value>.*</value>$#', $xml->asXML())) {
+                $value = str_replace(array('<value>', '</value>'), '', $xml->asXML());
+            }
         }
         }
     }
     }
 
 

+ 15 - 0
tests/Zend/XmlRpc/ValueTest.php

@@ -233,6 +233,21 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
         $this->assertSame($native, $val->getValue());
         $this->assertSame($native, $val->getValue());
     }
     }
 
 
+    public function testFactoryAutodetectsStringAndSetsValueInArray()
+    {
+        $val = Zend_XmlRpc_Value::getXmlRpcValue('<value><array><data>'.
+            '<value><i4>8</i4></value>'.
+            '<value>a</value>'.
+            '<value>false</value>'.
+            '</data></array></value>', Zend_XmlRpc_Value::XML_STRING
+        );
+        $this->assertXmlRpcType('array', $val);
+        $a = $val->getValue();
+        $this->assertSame(8, $a[0]);
+        $this->assertSame('a', $a[1]);
+        $this->assertSame('false', $a[2]);
+    }
+
     /**
     /**
      * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
      * @dataProvider Zend_XmlRpc_TestProvider::provideGenerators
      */
      */