mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Making Director::test() ignore URL Anchors
Anchors should never make it to the server when they are in the browser URL bar, however tests are slightly different and some `Link()` functions may return a URL anchor. Instead of every test checking a link and stripping the anchor, I feel the Director::test() function should strip them off.
This commit is contained in:
parent
7cbd7edfb7
commit
5e6c1b902b
@ -244,6 +244,10 @@ class Director implements TemplateGlobalProvider {
|
|||||||
Config::inst()->update('Cookie', 'report_errors', false);
|
Config::inst()->update('Cookie', 'report_errors', false);
|
||||||
Requirements::set_backend(new Requirements_Backend());
|
Requirements::set_backend(new Requirements_Backend());
|
||||||
|
|
||||||
|
if (strpos($url, '#') !== false) {
|
||||||
|
$url = substr($url, 0, strpos($url, '#'));
|
||||||
|
}
|
||||||
|
|
||||||
// Handle absolute URLs
|
// Handle absolute URLs
|
||||||
if (@parse_url($url, PHP_URL_HOST) != '') {
|
if (@parse_url($url, PHP_URL_HOST) != '') {
|
||||||
$bits = parse_url($url);
|
$bits = parse_url($url);
|
||||||
|
@ -344,6 +344,23 @@ class DirectorTest extends SapphireTest {
|
|||||||
|
|
||||||
$_SERVER = $origServer;
|
$_SERVER = $origServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTestIgnoresHashes() {
|
||||||
|
//test that hashes are ignored
|
||||||
|
$url = "DirectorTestRequest_Controller/returnGetValue?somekey=key";
|
||||||
|
$hash = "#test";
|
||||||
|
$response = Director::test($url . $hash, null, null, null, null, null, null, $request);
|
||||||
|
$this->assertFalse($response->isError());
|
||||||
|
$this->assertEquals('key', $response->getBody());
|
||||||
|
$this->assertEquals($request->getURL(true), $url);
|
||||||
|
|
||||||
|
//test encoded hashes are accepted
|
||||||
|
$url = "DirectorTestRequest_Controller/returnGetValue?somekey=test%23key";
|
||||||
|
$response = Director::test($url, null, null, null, null, null, null, $request);
|
||||||
|
$this->assertFalse($response->isError());
|
||||||
|
$this->assertEquals('test#key', $response->getBody());
|
||||||
|
$this->assertEquals($request->getURL(true), $url);
|
||||||
|
}
|
||||||
|
|
||||||
public function testRequestFilterInDirectorTest() {
|
public function testRequestFilterInDirectorTest() {
|
||||||
$filter = new TestRequestFilter;
|
$filter = new TestRequestFilter;
|
||||||
|
Loading…
Reference in New Issue
Block a user