Permalink
Browse files

Fix decoding of <string></string>.

An empty string represented using an empty "string" tag in expanded form
triggered an InvalidValueException while decoding.
Thanks to @thibaud-rohmer for bringing that issue to my attention through
IRC.
  • Loading branch information...
1 parent a87f6c2 commit c200056e7aa308efbcb4da77359dd5114a736a39 @fpoirotte committed Apr 12, 2012
Showing with 33 additions and 1 deletion.
  1. +10 −1 src/XRL/Decoder.php
  2. +14 −0 tests/DecoderTest.php
  3. +9 −0 tests/testdata/requests/string3.xml
View
11 src/XRL/Decoder.php
@@ -333,7 +333,16 @@ protected function _decodeValue($reader, array $allowedTypes = array())
continue;
}
- $value = $this->_parseText($reader);
+ try {
+ $value = $this->_parseText($reader);
+ }
+ catch (InvalidArgumentException $e) {
+ // Both "string" & "base64" may refer
+ // to an empty string.
+ if ($type != 'string' && $type != 'base64')
+ throw $e;
+ $value = '';
+ }
$this->_expectEndTag($reader, $type);
switch ($type) {
View
14 tests/DecoderTest.php
@@ -202,6 +202,20 @@ public function testDecodeRequestWithStringParameter2($xml)
/**
* @dataProvider requestProvider
*/
+ public function testDecodeRequestWithStringParameter3($xml)
+ {
+ $request = $this->_decoder->decodeRequest($xml);
+ $this->assertInstanceOf('XRL_Request', $request);
+
+ $params = $request->getParams();
+ $this->assertEquals('stringParam', $request->getProcedure());
+ $this->assertEquals(1, count($params));
+ $this->assertSame('test', $params[0]);
+ }
+
+ /**
+ * @dataProvider requestProvider
+ */
public function testDecodeRequestWithDoubleParameter($xml)
{
$request = $this->_decoder->decodeRequest($xml);
View
9 tests/testdata/requests/string3.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<methodCall>
+ <methodName>stringParam</methodName>
+ <params>
+ <param>
+ <value><string>test</string></value>
+ </param>
+ </params>
+</methodCall>

0 comments on commit c200056

Please sign in to comment.