Skip to content

Commit c22139a

Browse files
Merge branch '2.7' into 2.8
* 2.7: [DI] Add missing check in PhpDumper [Serializer] XmlEncoder: fix negative int and large numbers handling [Console] Fix dispatching throwables from ConsoleEvents::COMMAND
2 parents 2a6b382 + f88908e commit c22139a

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

Encoder/XmlEncoder.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,19 @@ private function parseXmlAttributes(\DOMNode $node)
301301
$data = array();
302302

303303
foreach ($node->attributes as $attr) {
304-
if (ctype_digit($attr->nodeValue)) {
305-
$data['@'.$attr->nodeName] = (int) $attr->nodeValue;
306-
} else {
304+
if (!is_numeric($attr->nodeValue)) {
307305
$data['@'.$attr->nodeName] = $attr->nodeValue;
306+
307+
continue;
308+
}
309+
310+
if (false !== $val = filter_var($attr->nodeValue, FILTER_VALIDATE_INT)) {
311+
$data['@'.$attr->nodeName] = $val;
312+
313+
continue;
308314
}
315+
316+
$data['@'.$attr->nodeName] = (float) $attr->nodeValue;
309317
}
310318

311319
return $data;

Tests/Encoder/XmlEncoderTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,46 @@ public function testDecodeScalar()
222222
$this->assertEquals('foo', $this->encoder->decode($source, 'xml'));
223223
}
224224

225+
public function testDecodeBigDigitAttributes()
226+
{
227+
$source = <<<XML
228+
<?xml version="1.0"?>
229+
<document index="182077241760011681341821060401202210011000045913000000017100">Name</document>
230+
XML;
231+
232+
$this->assertSame(array('@index' => 182077241760011681341821060401202210011000045913000000017100, '#' => 'Name'), $this->encoder->decode($source, 'xml'));
233+
}
234+
235+
public function testDecodeNegativeIntAttribute()
236+
{
237+
$source = <<<XML
238+
<?xml version="1.0"?>
239+
<document index="-1234">Name</document>
240+
XML;
241+
242+
$this->assertSame(array('@index' => -1234, '#' => 'Name'), $this->encoder->decode($source, 'xml'));
243+
}
244+
245+
public function testDecodeFloatAttribute()
246+
{
247+
$source = <<<XML
248+
<?xml version="1.0"?>
249+
<document index="-12.11">Name</document>
250+
XML;
251+
252+
$this->assertSame(array('@index' => -12.11, '#' => 'Name'), $this->encoder->decode($source, 'xml'));
253+
}
254+
255+
public function testDecodeNegativeFloatAttribute()
256+
{
257+
$source = <<<XML
258+
<?xml version="1.0"?>
259+
<document index="-12.11">Name</document>
260+
XML;
261+
262+
$this->assertSame(array('@index' => -12.11, '#' => 'Name'), $this->encoder->decode($source, 'xml'));
263+
}
264+
225265
public function testEncode()
226266
{
227267
$source = $this->getXmlSource();

0 commit comments

Comments
 (0)