Skip to content

Commit

Permalink
[5.3] Restore support for non-string needle in Str::startsWith() (#15397
Browse files Browse the repository at this point in the history
)

* Add test to prevent a potential regression

* Restore support for non-string needle

* Code unification
  • Loading branch information
vlakoff authored and taylorotwell committed Sep 12, 2016
1 parent e831a9a commit c7de016
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function contains($haystack, $needles)
public static function endsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ((string) $needle === substr($haystack, -strlen($needle))) {
if (substr($haystack, -strlen($needle)) === (string) $needle) {
return true;
}
}
Expand Down Expand Up @@ -403,7 +403,7 @@ public static function snake($value, $delimiter = '_')
public static function startsWith($haystack, $needles)
{
foreach ((array) $needles as $needle) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === $needle) {
if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testStartsWith()
$this->assertFalse(Str::startsWith('jason', 'day'));
$this->assertFalse(Str::startsWith('jason', ['day']));
$this->assertFalse(Str::startsWith('jason', ''));
$this->assertFalse(Str::startsWith('7', ' 7'));
}

public function testEndsWith()
Expand Down

0 comments on commit c7de016

Please sign in to comment.