From 39309b1e9a1e21a9ec16603a920ccf8faf87f880 Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 13 Jul 2009 04:15:40 +0000 Subject: [PATCH] ENHANCEMENT allow Director::test() to cope with absolute URIs git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@81680 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Director.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/control/Director.php b/core/control/Director.php index 408addfa1..c8c9b9a5f 100644 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -179,12 +179,6 @@ class Director { if(!$httpMethod) $httpMethod = ($postVars || is_array($postVars)) ? "POST" : "GET"; - $urlWithQuerystring = $url; - if(strpos($url, '?') !== false) { - list($url, $getVarsEncoded) = explode('?', $url, 2); - parse_str($getVarsEncoded, $getVars); - } - if(!$session) $session = new Session(null); // Back up the current values of the superglobals @@ -200,6 +194,19 @@ class Director { Cookie::set_report_errors(false); Requirements::set_backend(new Requirements_Backend()); + // Handle absolute URLs + if (@parse_url($url, PHP_URL_HOST) != '') { + $bits = parse_url($url); + $_SERVER['HTTP_HOST'] = $bits['host']; + $url = Director::makeRelative($url); + } + + $urlWithQuerystring = $url; + if(strpos($url, '?') !== false) { + list($url, $getVarsEncoded) = explode('?', $url, 2); + parse_str($getVarsEncoded, $getVars); + } + // Replace the superglobals with appropriate test values $_REQUEST = array_merge((array)$getVars, (array)$postVars); $_GET = (array)$getVars;