Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  fix merge
  Remove branch-version (keep them for contracts only)
  [HttpClient] relax auth bearer format requirements
  [PHPUnitBridge] Silence errors from mkdir()
  [DependencyInjection] Preload classes with union types correctly.
  [Serializer] fix decoding float XML attributes starting with 0
  add missing dutch translations
  Support PHPUnit 8 and PHPUnit 9 in constraint compatibility trait
  Add expectDeprecation, expectNotice, expectWarning, and expectError to TestCase polyfill
  Add missing exporter function for PHPUnit 7
  [Validator] Add missing romanian translations
  [Cache] Use correct expiry in ChainAdapter
  do not translate null placeholders or titles
  • Loading branch information
nicolas-grekas committed Oct 24, 2020
2 parents 80aa181 + 2af7e86 commit 20d3c6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = []): array
$typeCastAttributes = (bool) ($context[self::TYPE_CAST_ATTRIBUTES] ?? $this->defaultContext[self::TYPE_CAST_ATTRIBUTES]);

foreach ($node->attributes as $attr) {
if (!is_numeric($attr->nodeValue) || !$typeCastAttributes || (isset($attr->nodeValue[1]) && '0' === $attr->nodeValue[0])) {
if (!is_numeric($attr->nodeValue) || !$typeCastAttributes || (isset($attr->nodeValue[1]) && '0' === $attr->nodeValue[0] && '.' !== $attr->nodeValue[1])) {
$data['@'.$attr->nodeName] = $attr->nodeValue;

continue;
Expand Down
14 changes: 12 additions & 2 deletions Tests/Encoder/XmlEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ public function testDecodeFloatAttribute()
{
$source = <<<XML
<?xml version="1.0"?>
<document index="-12.11">Name</document>
<document index="12.11">Name</document>
XML;

$this->assertSame(['@index' => -12.11, '#' => 'Name'], $this->encoder->decode($source, 'xml'));
$this->assertSame(['@index' => 12.11, '#' => 'Name'], $this->encoder->decode($source, 'xml'));
}

public function testDecodeNegativeFloatAttribute()
Expand All @@ -292,6 +292,16 @@ public function testDecodeNegativeFloatAttribute()
$this->assertSame(['@index' => -12.11, '#' => 'Name'], $this->encoder->decode($source, 'xml'));
}

public function testDecodeFloatAttributeWithZeroWholeNumber()
{
$source = <<<XML
<?xml version="1.0"?>
<document index="0.123">Name</document>
XML;

$this->assertSame(['@index' => 0.123, '#' => 'Name'], $this->encoder->decode($source, 'xml'));
}

public function testNoTypeCastAttribute()
{
$source = <<<XML
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,5 @@
"/Tests/"
]
},
"minimum-stability": "dev",
"extra": {
"branch-version": "5.1"
}
"minimum-stability": "dev"
}

0 comments on commit 20d3c6c

Please sign in to comment.