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
6 changes: 3 additions & 3 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public static function trimSplit(?string $subject, string $delimiter = ',', ?int
/**
* Check if the given string is empty
*
* Null is considered empty, and strings consisting only of whitespace or visually
* empty characters are considered empty.
* Null is considered empty, and strings consisting only of whitespace, NUL bytes,
* or visually empty characters are considered empty.
*
* @param string|Stringable|null $subject
*
* @return bool
*/
public static function isEmpty(string|Stringable|null $subject): bool
{
return $subject === null || preg_match('/^[\s\x{3164}\x{1160}]*$/u', $subject) === 1;
return $subject === null || preg_match('/^[\s\x00\x{3164}\x{1160}]*$/u', $subject) === 1;
}
}
10 changes: 10 additions & 0 deletions tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public function testIsEmptyReturnsTrueForStringWithOnlyWhitespace()
$this->assertTrue(Str::isEmpty("\t\n"));
}

public function testIsEmptyReturnsTrueForNulByte()
{
$this->assertTrue(Str::isEmpty("\0"));
}

public function testIsEmptyReturnsTrueForNulByteCombinedWithWhitespace()
{
$this->assertTrue(Str::isEmpty("\0 "));
}

public function testIsEmptyReturnsFalseForZero()
{
$this->assertFalse(Str::isEmpty('0'));
Expand Down
Loading