mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Support for protocol relative RedirectorPage.ExternalURL
This commit is contained in:
parent
6a69134fb0
commit
40f7a876d4
@ -107,7 +107,11 @@ class RedirectorPage extends Page {
|
|||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
|
|
||||||
// Prefix the URL with "http://" if no prefix is found
|
// Prefix the URL with "http://" if no prefix is found
|
||||||
if($this->ExternalURL && (strpos($this->ExternalURL, '://') === false)) {
|
if(
|
||||||
|
$this->ExternalURL
|
||||||
|
&& !parse_url($this->ExternalURL, PHP_URL_SCHEME)
|
||||||
|
&& !preg_match('#^//#', $this->ExternalURL)
|
||||||
|
) {
|
||||||
$this->ExternalURL = 'http://' . $this->ExternalURL;
|
$this->ExternalURL = 'http://' . $this->ExternalURL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,4 +50,18 @@ class RedirectorPageTest extends FunctionalTest {
|
|||||||
$page->write();
|
$page->write();
|
||||||
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
|
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAllowsProtocolRelative() {
|
||||||
|
$noProtocol = new RedirectorPage(array('ExternalURL' => 'mydomain.com'));
|
||||||
|
$noProtocol->write();
|
||||||
|
$this->assertEquals('http://mydomain.com', $noProtocol->ExternalURL);
|
||||||
|
|
||||||
|
$protocolAbsolute = new RedirectorPage(array('ExternalURL' => 'http://mydomain.com'));
|
||||||
|
$protocolAbsolute->write();
|
||||||
|
$this->assertEquals('http://mydomain.com', $protocolAbsolute->ExternalURL);
|
||||||
|
|
||||||
|
$protocolRelative = new RedirectorPage(array('ExternalURL' => '//mydomain.com'));
|
||||||
|
$protocolRelative->write();
|
||||||
|
$this->assertEquals('//mydomain.com', $protocolRelative->ExternalURL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user