Merge pull request #1768 from tractorcow/3.1-http-mail-fixes

BUG HTTP incorrectly converts mailto links to absolute urls
This commit is contained in:
Sean Harvey 2013-04-18 14:46:10 -07:00
commit 6e0fa5db45
2 changed files with 13 additions and 0 deletions

View File

@ -42,6 +42,7 @@ class HTTP {
public static function absoluteURLs($html) {
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
return HTTP::urlRewriter($html, function($url) {
if(stripos($url, 'mailto:') === 0) return $url;
return Director::absoluteURL($url, true);
});
}

View File

@ -187,6 +187,18 @@ class HTTPTest extends SapphireTest {
});
}
public function testEmailLinks() {
$this->withBaseURL('http://www.silverstripe.org/', function($test){
// links
$test->assertEquals(
'<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>',
HTTP::absoluteURLs('<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>')
);
});
}
/**
* Run a test while mocking the base url with the provided value
* @param string $url The base URL to use for this test