Skip to content

[Serializer] XmlEncoder: don't cast padded strings #32438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Serializer] XmlEncoder: don't cast padded strings
  • Loading branch information
ogizanagi committed Jul 8, 2019
commit c1bfaa1de489b51de89d4320c615b2c65bf81f17
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = [])
$typeCastAttributes = $this->resolveXmlTypeCastAttributes($context);

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

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ public function testNoTypeCastAttribute()
$this->assertSame($expected, $data);
}

public function testDoesNotTypeCastStringsStartingWith0()
{
$source = <<<XML
<?xml version="1.0"?>
<document a="018"></document>
XML;

$data = $this->encoder->decode($source, 'xml');
$this->assertSame('018', $data['@a']);
}

public function testEncode()
{
$source = $this->getXmlSource();
Expand Down