From 3b1a6293a29ca8cc8d1ef0d20f55e7758983fb8b Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 11 Aug 2008 05:26:51 +0000 Subject: [PATCH] BUGFIX: Fixed superglobal masquerading in Director::test() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60393 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Director.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/control/Director.php b/core/control/Director.php index 9eb9192b4..b2f5b42ae 100644 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -153,11 +153,29 @@ class Director { list($url, $getVarsEncoded) = explode('?', $url, 2); parse_str($getVarsEncoded, $getVars); } - if(!$session) $session = new Session(null); + + // Back up the current values of the superglobals + $existingRequestVars = $_REQUEST; + $existingGetVars = $_GET; + $existingPostVars = $_POST; + $existingSessionVars = $_SESSION; + + // Replace the superglobals with appropriate test values + $_REQUEST = array_merge((array)$getVars, (array)$post); + $_GET = (array)$getVars; + $_POST = (array)$post; + $_SESSION = $session ? $session->inst_getAll() : array(); + $req = new HTTPRequest($httpMethod, $url, $getVars, $postVars, $body); if($headers) foreach($headers as $k => $v) $req->addHeader($k, $v); $result = Director::handleRequest($req, $session); + + // Restore the superglobals + $_REQUEST = $existingRequestVars; + $_GET = $existingGetVars; + $_POST = $existingPostVars; + $_SESSION = $existingSessionVars; return $result; }