Skip to content

Commit 7d556ff

Browse files
committed
fix isHttp
1 parent 2fd94aa commit 7d556ff

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function resolveUri(UriInterface $base, UriInterface $uri): UriInterface
6363

6464
function isHttp(string $uri): bool
6565
{
66-
if (preg_match('/^(w+):/', $uri, $matches)) {
66+
if (preg_match('/^(\w+):/', $uri, $matches)) {
6767
return in_array(strtolower($matches[1]), ['http', 'https']);
6868
}
6969

tests/FunctionsTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Embed\Tests;
5+
6+
use function Embed\isHttp;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class FunctionsTest extends TestCase
10+
{
11+
public function urlsProvider(): array
12+
{
13+
return [
14+
['https://foo.com', true],
15+
['http://foo.com', true],
16+
['mailto:foo@example.com', false],
17+
['tel:+1234567890', false],
18+
['data:foo', false],
19+
['./foo', true],
20+
['/foo', true],
21+
['../foo', true],
22+
['foo.com', true],
23+
['//foo.com', true],
24+
];
25+
}
26+
27+
/**
28+
* @dataProvider urlsProvider
29+
*/
30+
public function testIsHttp(string $url, bool $expected)
31+
{
32+
$result = isHttp($url);
33+
$this->assertSame($expected, $result);
34+
}
35+
}

0 commit comments

Comments
 (0)