Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let Str::isUrl() check more URLs #2759

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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