Commit ebe86d20 authored by Mattias Geniar's avatar Mattias Geniar
Browse files

Add support for simple mailto: links

parent fffea8b2
......@@ -34,7 +34,7 @@ class Url implements UriInterface
/** @var string */
protected $fragment = '';
const VALID_SCHEMES = ['http', 'https'];
const VALID_SCHEMES = ['http', 'https', 'mailto'];
public function __construct()
{
......@@ -311,10 +311,14 @@ class Url implements UriInterface
{
$url = '';
if ($this->getScheme() !== '') {
if ($this->getScheme() !== '' && $this->getScheme() != 'mailto') {
$url .= $this->getScheme().'://';
}
if ($this->getScheme() === 'mailto' && $this->getPath() !== '') {
$url .= $this->getScheme().':';
}
if ($this->getScheme() === '' && $this->getAuthority() !== '') {
$url .= '//';
}
......
......@@ -22,4 +22,12 @@ class UrlMatchesTest extends TestCase
$this->assertFalse($url->matches(Url::fromString('https://spatie.be/opensource')));
}
/** @test */
public function it_can_check_if_it_contains_a_mailto()
{
$url = Url::fromString('mailto:email@domain.tld');
$this->assertTrue($url->matches(Url::fromString('mailto:email@domain.tld')));
}
}
......@@ -24,6 +24,14 @@ class UrlParseTest extends TestCase
$this->assertEquals('https', $url->getScheme());
}
/** @test */
public function it_can_parse_a_scheme_with_mailto()
{
$url = Url::fromString('mailto:email@domain.tld');
$this->assertEquals('mailto', $url->getScheme());
}
/** @test */
public function it_throws_an_exception_if_an_invalid_scheme_is_provided()
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment