Skip to content

Commit 1926101

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [BrowserKit] Merge fields and files recursively if they are multidimensional array [String] Fix `width` method in `AbstractUnicodeString` [Mailer] Add a comment to avoid the same wrong PR over and over again [Serializer] Fix XmlEncoder encoding attribute false
2 parents 779928e + 443f8c3 commit 1926101

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Encoder/XmlEncoder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ private function buildXml(\DOMNode $parentNode, mixed $data, string $format, arr
357357
if (!\is_scalar($data)) {
358358
$data = $this->serializer->normalize($data, $format, $context);
359359
}
360+
if (\is_bool($data)) {
361+
$data = (int) $data;
362+
}
360363
$parentNode->setAttribute($attributeName, $data);
361364
} elseif ('#' === $key) {
362365
$append = $this->selectNodeType($parentNode, $data, $format, $context);

Tests/Encoder/XmlEncoderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public function testAttributes()
9696
'föo_bär' => 'a',
9797
'Bar' => [1, 2, 3],
9898
'a' => 'b',
99+
'scalars' => [
100+
'@bool-true' => true,
101+
'@bool-false' => false,
102+
'@int' => 3,
103+
'@float' => 3.4,
104+
'@sring' => 'a',
105+
],
99106
];
100107
$expected = '<?xml version="1.0"?>'."\n".
101108
'<response>'.
@@ -106,6 +113,7 @@ public function testAttributes()
106113
'<Bar>2</Bar>'.
107114
'<Bar>3</Bar>'.
108115
'<a>b</a>'.
116+
'<scalars bool-true="1" bool-false="0" int="3" float="3.4" sring="a"/>'.
109117
'</response>'."\n";
110118
$this->assertEquals($expected, $this->encoder->encode($obj, 'xml'));
111119
}

0 commit comments

Comments
 (0)