Skip to content

Commit

Permalink
Let Str::isUrl() check more URLs (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored Oct 28, 2020
1 parent 9c11220 commit 0432503
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ public function isUppercase($value)
*/
public function isUrl($value)
{
return filter_var($value, FILTER_VALIDATE_URL) !== false;
return Str::isUrl($value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function slugToTitle($string)

public static function isUrl($string)
{
return self::startsWith($string, ['http://', 'https://', '/']);
return self::startsWith($string, '/') || filter_var($string, FILTER_VALIDATE_URL) !== false;
}

public static function deslugify($string)
Expand Down
2 changes: 2 additions & 0 deletions tests/Support/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function it_checks_for_a_url()
{
$this->assertTrue(Str::isUrl('http://example.com'));
$this->assertTrue(Str::isUrl('https://example.com'));
$this->assertTrue(Str::isUrl('ftp://example.com'));
$this->assertTrue(Str::isUrl('mailto:[email protected]'));
$this->assertTrue(Str::isUrl('/relative'));
$this->assertFalse(Str::isUrl('test'));
}
Expand Down

0 comments on commit 0432503

Please sign in to comment.