Permalink
Browse files

fixed some special urls like mailto:, javascript:, etc

  • Loading branch information...
oscarotero committed Sep 9, 2018
1 parent 87aa0ed commit dcb176e504f9ae26cf25de42e50130c0600af0d6
Showing with 22 additions and 1 deletion.
  1. +1 −1 src/Http/Url.php
  2. +21 −0 tests/UrlTest.php
View
@@ -559,7 +559,7 @@ public function getAbsolute($url)
return '';
}
if (strpos($url, 'data:') === 0) {
if (preg_match('|^\w+:[^/]|', $url)) {
return $url;
}
View
@@ -151,4 +151,25 @@ public function testUrlMatch($url, $pattern, $expected)
$url = Url::create($url);
$this->assertSame($expected, $url->match($pattern));
}
public function urlAbsoluteProvider()
{
return [
['other-path', 'http://example.com/other-path'],
['//other.com/path', 'http://other.com/path'],
['data:base64', 'data:base64'],
['', ''],
['mailto:hello@example.com', 'mailto:hello@example.com'],
];
}
/**
* @dataProvider urlAbsoluteProvider
*/
public function testAbsoluteUrl($added, $expected)
{
$url = Url::create('http://example.com/path');
$this->assertSame($expected, $url->getAbsolute($added));
}
}

0 comments on commit dcb176e

Please sign in to comment.