Skip to content

Commit fb5cd82

Browse files
committed
serialize empty HTML
1 parent c5797af commit fb5cd82

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Drivers/HtmlDriver.php

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public function serialize($data): string
1515
throw new CantBeSerialized('Only strings can be serialized to html');
1616
}
1717

18+
if ('' === $data) {
19+
return "\n";
20+
}
21+
1822
$domDocument = new DOMDocument('1.0');
1923
$domDocument->preserveWhiteSpace = false;
2024
$domDocument->formatOutput = true;

tests/Unit/Drivers/HtmlDriverTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@ public function it_can_only_serialize_strings()
7171

7272
$driver->serialize(['foo' => 'bar']);
7373
}
74+
75+
/** @test */
76+
public function it_can_serialize_an_empty_string()
77+
{
78+
$driver = new HtmlDriver();
79+
80+
$this->assertEquals("\n", $driver->serialize(''));
81+
}
7482
}

0 commit comments

Comments
 (0)