Skip to content

Commit ab2ad88

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [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 [HttpFoundation] Fix `\Stringable` support in `InputBag::get()`
2 parents 5f1acdd + cb46cdf commit ab2ad88

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
@@ -361,6 +361,9 @@ private function buildXml(\DOMNode $parentNode, mixed $data, string $format, arr
361361
if (!\is_scalar($data)) {
362362
$data = $this->serializer->normalize($data, $format, $context);
363363
}
364+
if (\is_bool($data)) {
365+
$data = (int) $data;
366+
}
364367
$parentNode->setAttribute($attributeName, $data);
365368
} elseif ('#' === $key) {
366369
$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)