From 620fdda54c084123b9550c885301ef9a13f7edff Mon Sep 17 00:00:00 2001 From: feycot Date: Sun, 4 Oct 2020 15:59:37 +0500 Subject: [PATCH 1/3] strict types for replaceFirst --- src/Illuminate/Support/Str.php | 3 ++- tests/Support/SupportStrTest.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 59158f4c6ee7..450b80f82e30 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -501,7 +501,8 @@ public static function replaceArray($search, array $replace, $subject) */ public static function replaceFirst($search, $replace, $subject) { - if ($search == '') { + $search = (string)$search; + if ($search === '') { return $subject; } diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 87bc3c0956c4..6d930ec375f1 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -348,6 +348,7 @@ public function testReplaceFirst() $this->assertSame('foo foobar', Str::replaceFirst('bar', '', 'foobar foobar')); $this->assertSame('foobar foobar', Str::replaceFirst('xxx', 'yyy', 'foobar foobar')); $this->assertSame('foobar foobar', Str::replaceFirst('', 'yyy', 'foobar foobar')); + $this->assertSame('1', Str::replaceFirst(0, '1', '0')); // Test for multibyte string support $this->assertSame('Jxxxnköping Malmö', Str::replaceFirst('ö', 'xxx', 'Jönköping Malmö')); $this->assertSame('Jönköping Malmö', Str::replaceFirst('', 'yyy', 'Jönköping Malmö')); From b4e26e774dd9fb10de1f7943c89466859c4f3105 Mon Sep 17 00:00:00 2001 From: feycot Date: Sun, 4 Oct 2020 16:04:03 +0500 Subject: [PATCH 2/3] add strict str_is --- src/Illuminate/Support/Str.php | 4 ++-- tests/Support/SupportStrTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 450b80f82e30..8989edaacb81 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -251,7 +251,7 @@ public static function is($pattern, $value) // If the given value is an exact match we can of course return true right // from the beginning. Otherwise, we will translate asterisks and do an // actual pattern match against the two strings to see if they match. - if ($pattern == $value) { + if ($pattern === $value) { return true; } @@ -501,7 +501,7 @@ public static function replaceArray($search, array $replace, $subject) */ public static function replaceFirst($search, $replace, $subject) { - $search = (string)$search; + $search = (string) $search; if ($search === '') { return $subject; } diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 6d930ec375f1..c39a65ea4ab9 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -264,6 +264,10 @@ public function testIs() // empty patterns $this->assertFalse(Str::is([], 'test')); + + $this->assertFalse(Str::is('', 0)); + $this->assertFalse(Str::is([null], 0)); + $this->assertTrue(Str::is([null], null)); } /** From 36bf4c406ae0e17e3e018bae0078f30b762573d6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 5 Oct 2020 07:51:13 -0500 Subject: [PATCH 3/3] Update Str.php --- src/Illuminate/Support/Str.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 8989edaacb81..86f0537139b5 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -502,6 +502,7 @@ public static function replaceArray($search, array $replace, $subject) public static function replaceFirst($search, $replace, $subject) { $search = (string) $search; + if ($search === '') { return $subject; }