Skip to content

Commit 47fedaf

Browse files
Merge branch '2.8' into 3.2
* 2.8: Fixed the flickering when loading complex profiler panels [DI] Add missing check in PhpDumper [Serializer] XmlEncoder: fix negative int and large numbers handling [Console] Fix dispatching throwables from ConsoleEvents::COMMAND
2 parents 7f7f798 + c22139a commit 47fedaf

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
@@ -304,11 +304,19 @@ private function parseXmlAttributes(\DOMNode $node)
304304
$data = array();
305305

306306
foreach ($node->attributes as $attr) {
307-
if (ctype_digit($attr->nodeValue)) {
308-
$data['@'.$attr->nodeName] = (int) $attr->nodeValue;
309-
} else {
307+
if (!is_numeric($attr->nodeValue)) {
310308
$data['@'.$attr->nodeName] = $attr->nodeValue;
309+
310+
continue;
311+
}
312+
313+
if (false !== $val = filter_var($attr->nodeValue, FILTER_VALIDATE_INT)) {
314+
$data['@'.$attr->nodeName] = $val;
315+
316+
continue;
311317
}
318+
319+
$data['@'.$attr->nodeName] = (float) $attr->nodeValue;
312320
}
313321

314322
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)