diff --git a/src/Str.php b/src/Str.php index c7ab22b..2e23fd8 100644 --- a/src/Str.php +++ b/src/Str.php @@ -96,8 +96,8 @@ 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 * @@ -105,6 +105,6 @@ public static function trimSplit(?string $subject, string $delimiter = ',', ?int */ 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; } } diff --git a/tests/StrTest.php b/tests/StrTest.php index bcff7db..8347d12 100644 --- a/tests/StrTest.php +++ b/tests/StrTest.php @@ -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'));