Skip to content

Commit

Permalink
Handle binary data
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomeara committed Mar 29, 2024
1 parent 46e802a commit 47941b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ public static function snake($value, $delimiter = '_')
public static function trim($value, $charlist = null)
{
if ($charlist === null) {
return preg_replace('~^[\s\x{FEFF}\x{200B}]+|[\s\x{FEFF}\x{200B}]+$~u', '', $value);
return preg_replace('~^[\s\x{FEFF}\x{200B}]+|[\s\x{FEFF}\x{200B}]+$~u', '', $value) ?? trim($value);
}

return trim($value, $charlist);
Expand All @@ -1444,7 +1444,7 @@ public static function trim($value, $charlist = null)
public static function ltrim($value, $charlist = null)
{
if ($charlist === null) {
return preg_replace('~^[\s\x{FEFF}\x{200B}]+~u', '', $value);
return preg_replace('~^[\s\x{FEFF}\x{200B}]+~u', '', $value) ?? ltrim($value);
}

return ltrim($value, $charlist);
Expand All @@ -1460,7 +1460,7 @@ public static function ltrim($value, $charlist = null)
public static function rtrim($value, $charlist = null)
{
if ($charlist === null) {
return preg_replace('~[\s\x{FEFF}\x{200B}]+$~u', '', $value);
return preg_replace('~[\s\x{FEFF}\x{200B}]+$~u', '', $value) ?? rtrim($value);
}

return rtrim($value, $charlist);
Expand Down
5 changes: 5 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ public function testTrim()
bar
')
);

$this->assertSame("\xE9", Str::trim(" \xE9 "));
}

public function testLtrim()
Expand All @@ -817,6 +819,7 @@ public function testLtrim()
foo bar
')
);
$this->assertSame("\xE9 ", Str::ltrim(" \xE9 "));
}

public function testRtrim()
Expand All @@ -836,6 +839,8 @@ public function testRtrim()
foo bar
')
);

$this->assertSame(" \xE9", Str::rtrim(" \xE9 "));
}

public function testSquish()
Expand Down

0 comments on commit 47941b4

Please sign in to comment.