Skip to content
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
4 changes: 2 additions & 2 deletions src/Illuminate/Support/HtmlString.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function toHtml()
*/
public function isEmpty()
{
return $this->html === '';
return ($this->html ?? '') === '';
}

/**
Expand All @@ -62,6 +62,6 @@ public function isNotEmpty()
*/
public function __toString()
{
return $this->toHtml();
return $this->toHtml() ?? '';
}
}
7 changes: 7 additions & 0 deletions tests/Support/SupportHtmlStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ public function testToString()
$str = '<h1>foo</h1>';
$html = new HtmlString('<h1>foo</h1>');
$this->assertEquals($str, (string) $html);

// Check if HtmlString gracefully handles a null value
$html = new HtmlString(null);
$this->assertIsString((string) $html);
}

public function testIsEmpty(): void
{
// Check if HtmlString correctly identifies an empty string as empty
$this->assertTrue((new HtmlString(''))->isEmpty());

// Check if HtmlString identifies a null value as empty
$this->assertTrue((new HtmlString(null))->isEmpty());

// HtmlString with whitespace should not be considered as empty
$this->assertFalse((new HtmlString(' '))->isEmpty());

Expand Down