Skip to content

Commit dcd3ce6

Browse files
vdbeltfreekmurze
authored andcommitted
Fix for zero values interpreted as empty (spatie#112)
1 parent 68a1812 commit dcd3ce6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/ArrayToXml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ protected function addCollectionNode(DOMElement $element, $value)
168168

169169
protected function addSequentialNode(DOMElement $element, $value)
170170
{
171-
if (empty($element->nodeValue)) {
171+
if (empty($element->nodeValue) && ! is_numeric($element->nodeValue)) {
172172
$element->nodeValue = htmlspecialchars($value);
173173

174174
return;

tests/ArrayToXmlTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public function it_can_handle_values_as_basic_collection()
106106
]));
107107
}
108108

109+
/** @test */
110+
public function it_can_handle_zero_values_in_beginning_of_basic_collection()
111+
{
112+
$this->assertMatchesXmlSnapshot(ArrayToXml::convert([
113+
'user' => ['0', '1', '0'],
114+
]));
115+
}
116+
109117
/** @test */
110118
public function it_accepts_an_xml_encoding_type()
111119
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<root>
3+
<user>0</user>
4+
<user>1</user>
5+
<user>0</user>
6+
</root>

0 commit comments

Comments
 (0)