Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Making Director::test() ignore URL Anchors #2901

Merged
merged 1 commit into from

2 participants

@dhensby
Collaborator

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.

@dhensby dhensby 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.
5e6c1b9
@simonwelsh simonwelsh merged commit d1befdd into from
@dhensby
Collaborator

Thanks

@dhensby dhensby deleted the branch
@dhensby
Collaborator

@simonwelsh / @chillu - can we get this into 3.1, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2014
  1. @dhensby

    Making Director::test() ignore URL Anchors

    dhensby authored
    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 page is out of date. Refresh to see the latest.
Showing with 21 additions and 0 deletions.
  1. +4 −0 control/Director.php
  2. +17 −0 tests/control/DirectorTest.php
View
4 control/Director.php
@@ -244,6 +244,10 @@ public static function test($url, $postVars = null, $session = null, $httpMethod
Config::inst()->update('Cookie', 'report_errors', false);
Requirements::set_backend(new Requirements_Backend());
+ if (strpos($url, '#') !== false) {
+ $url = substr($url, 0, strpos($url, '#'));
+ }
+
// Handle absolute URLs
if (@parse_url($url, PHP_URL_HOST) != '') {
$bits = parse_url($url);
View
17 tests/control/DirectorTest.php
@@ -344,6 +344,23 @@ public function testIsHttps() {
$_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() {
$filter = new TestRequestFilter;
Something went wrong with that request. Please try again.