Skip to content
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
8 changes: 7 additions & 1 deletion src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,13 @@ public static function isUrl($value, array $protocols = [])
(LARAVEL_PROTOCOLS):// # protocol
(((?:[\_\.\pL\pN-]|%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%[0-9A-Fa-f]{2})+)@)? # basic auth
(
([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
(?:
(?:xn--[a-z0-9-]++\.)*+xn--[a-z0-9-]++ # a domain name using punycode
|
(?:[\pL\pN\pS\pM\-\_]++\.)+[\pL\pN\pM]++ # a multi-level domain name
|
[a-z0-9\-\_]++ # a single-level domain name
)\.?
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or
Expand Down
10 changes: 10 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,17 @@ public function testIsUrl()
{
$this->assertTrue(Str::isUrl('https://laravel.com'));
$this->assertTrue(Str::isUrl('http://localhost'));
$this->assertTrue(Str::isUrl('http://l'));
$this->assertTrue(Str::isUrl('http://l:8000'));
$this->assertTrue(Str::isUrl('http://l:8000/path'));
$this->assertTrue(Str::isUrl('http://a.b'));
$this->assertTrue(Str::isUrl('http://sub.domain.com'));
$this->assertTrue(Str::isUrl('http://my-site.com'));
$this->assertTrue(Str::isUrl('https://example.com:8080/path?q=1#frag'));
$this->assertFalse(Str::isUrl('invalid url'));
$this->assertFalse(Str::isUrl('http://.'));
$this->assertFalse(Str::isUrl('http://...'));
$this->assertFalse(Str::isUrl('http:///path'));
}

#[DataProvider('validUuidList')]
Expand Down
Loading