FIX for #5279 Addressing only a few PSR-2 items in one file, but primarily targeting Director::is_https() and invalid URL's.

This commit is contained in:
Patrick Nelson 2016-04-06 18:13:31 -07:00
parent 3572e2eaf4
commit 0aec89d0c8
2 changed files with 113 additions and 111 deletions

View File

@ -349,7 +349,11 @@ class Director implements TemplateGlobalProvider {
$_SERVER['REQUEST_URI'] = Director::baseURL() . $urlWithQuerystring;
$request = new SS_HTTPRequest($httpMethod, $url, $getVars, $postVars, $body);
if($headers) foreach($headers as $k => $v) $request->addHeader($k, $v);
if ($headers) {
foreach($headers as $k => $v) {
$request->addHeader($k, $v);
}
}
// Pre-request filtering
// @see issue #2517
@ -548,11 +552,15 @@ class Director implements TemplateGlobalProvider {
return Director::protocol() . $_SERVER['HTTP_HOST'];
} else {
global $_FILE_TO_URL_MAPPING;
if(Director::is_cli() && isset($_FILE_TO_URL_MAPPING)) $errorSuggestion = ' You probably want to define '.
if (Director::is_cli() && isset($_FILE_TO_URL_MAPPING)) {
$errorSuggestion = ' You probably want to define ' .
'an entry in $_FILE_TO_URL_MAPPING that covers "' . Director::baseFolder() . '"';
else if(Director::is_cli()) $errorSuggestion = ' You probably want to define $_FILE_TO_URL_MAPPING in '.
} elseif (Director::is_cli()) {
$errorSuggestion = ' You probably want to define $_FILE_TO_URL_MAPPING in ' .
'your _ss_environment.php as instructed on the "sake" page of the doc.silverstripe.com wiki';
else $errorSuggestion = "";
} else {
$errorSuggestion = "";
}
user_error("Director::protocolAndHost() lacks sufficient information - HTTP_HOST not set."
. $errorSuggestion, E_USER_WARNING);
@ -576,10 +584,8 @@ class Director implements TemplateGlobalProvider {
* @return bool
*/
public static function is_https() {
$return = false;
// See https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
// See https://support.microsoft.com/?kbID=307347
// See https://support.microsoft.com/en-us/kb/307347
$headerOverride = false;
if (TRUSTED_PROXY) {
$headers = (defined('SS_TRUSTED_PROXY_PROTOCOL_HEADER')) ? array(SS_TRUSTED_PROXY_PROTOCOL_HEADER) : null;
@ -597,18 +603,16 @@ class Director implements TemplateGlobalProvider {
}
if ($protocol = Config::inst()->get('Director', 'alternate_protocol')) {
$return = ($protocol == 'https');
return ($protocol == 'https');
} elseif ($headerOverride) {
$return = true;
return true;
} elseif ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')) {
$return = true;
return true;
} elseif (isset($_SERVER['SSL'])) {
$return = true;
return true;
} else {
$return = false;
return false;
}
return $return;
}
/**
@ -699,11 +703,9 @@ class Director implements TemplateGlobalProvider {
// If we are already looking at baseURL, return '' (substr will return false)
if ($url == $base1) {
return '';
}
else if(substr($url,0,strlen($base1)) == $base1) {
} elseif (substr($url, 0, strlen($base1)) == $base1) {
return substr($url, strlen($base1));
}
else if(substr($base1,-1)=="/" && $url == substr($base1,0,-1)) {
} elseif (substr($base1, -1) == "/" && $url == substr($base1, 0, -1)) {
// Convert http://www.mydomain.com/mysitedir to ''
return "";
}

View File

@ -164,7 +164,7 @@ class ParameterConfirmationToken {
// Are we http or https? Replicates Director::is_https() without its dependencies/
$proto = 'http';
// See https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
// See https://support.microsoft.com/?kbID=307347
// See https://support.microsoft.com/en-us/kb/307347
$headerOverride = false;
if(TRUSTED_PROXY) {
$headers = (defined('SS_TRUSTED_PROXY_PROTOCOL_HEADER')) ? array(SS_TRUSTED_PROXY_PROTOCOL_HEADER) : null;