diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 9594655fe4b0..55c3e82c3ecd 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -38,13 +38,17 @@ class Str */ public static function after($subject, $search) { - if (! static::contains($subject, $search)) { + if ($search == '') { return $subject; } - $end = strpos($subject, $search) + static::length($search); + $pos = strpos($subject, $search); - return static::substr($subject, $end, static::length($subject)); + if ($pos === false) { + return $subject; + } + + return substr($subject, $pos + strlen($search)); } /** diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index c3e84463cf18..eb3a03927330 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -80,7 +80,9 @@ public function testStrAfter() { $this->assertEquals('nah', Str::after('hannah', 'han')); $this->assertEquals('nah', Str::after('hannah', 'n')); + $this->assertEquals('nah', Str::after('ééé hannah', 'han')); $this->assertEquals('hannah', Str::after('hannah', 'xxxx')); + $this->assertEquals('hannah', Str::after('hannah', '')); } public function testStrContains()