BUGFIX #5259 RedirectorPage and HtmlEditorField TinyMCE integration now prefixes http:// if no prefix is found (from r101668)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112016 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-13 00:57:45 +00:00
parent 5aa012335a
commit 7d3d9a005e
4 changed files with 28 additions and 6 deletions

View File

@ -103,7 +103,16 @@ class RedirectorPage extends Page {
$this->HasBrokenLink = false;
}
}
function onBeforeWrite() {
parent::onBeforeWrite();
// Prefix the URL with "http://" if no prefix is found
if($this->ExternalURL && (strpos($this->ExternalURL, '://') === false)) {
$this->ExternalURL = 'http://' . $this->ExternalURL;
}
}
function getCMSFields() {
Requirements::javascript(SAPPHIRE_DIR . "/javascript/RedirectorPage.js");
@ -169,5 +178,4 @@ class RedirectorPage_Controller extends Page_Controller {
_t('RedirectorPage.HASBEENSETUP', 'A redirector page has been set up without anywhere to redirect to.') .
"</p>";
}
}
?>
}

View File

@ -199,7 +199,11 @@ LinkForm.prototype = {
case 'external':
default:
href = this.elements.external.value;
href = this.elements.external.value;
// Prefix the URL with "http://" if no prefix is found
if(href.indexOf('://') == -1) {
href = 'http://' + href;
}
if($('Form_EditorToolbarLinkForm_TargetBlank')) {
if($('Form_EditorToolbarLinkForm_TargetBlank').checked) target = '_blank';
}

View File

@ -43,6 +43,11 @@ class RedirectorPageTest extends FunctionalTest {
$response = $this->get(Director::makeRelative($page->Link()));
$this->assertEquals(Director::baseURL() . "redirection-dest/", $response->getHeader("Location"));
}
}
?>
function testExternalURLGetsPrefixIfNotSet() {
$page = $this->objFromFixture('RedirectorPage', 'externalnoprefix');
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite has prefixed with http');
$page->write();
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
}
}

View File

@ -18,6 +18,11 @@ RedirectorPage:
Title: Bad External
RedirectionType: External
URLSegment: bad-external
externalnoprefix:
Title: External no prefix
RedirectionType: External
URLSegment: external-no-prefix
ExternalURL: google.com
badinternal:
Title: Bad Internal
RedirectionType: Internal