Skip to content

Commit

Permalink
Updating env(HTTPS); to more accurately reflect the PHP $_SERVER docs.
Browse files Browse the repository at this point in the history
…Fixes #6524

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8246 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Jul 22, 2009
1 parent d6a12ce commit 7ca8510
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cake/basics.php
Expand Up @@ -362,8 +362,8 @@ function am() {
*/
function env($key) {
if ($key == 'HTTPS') {
if (isset($_SERVER) && !empty($_SERVER)) {
return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
if (isset($_SERVER['HTTPS'])) {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
}
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
}
Expand Down
17 changes: 17 additions & 0 deletions cake/tests/cases/basics.test.php
Expand Up @@ -94,11 +94,28 @@ function testEnv() {

$_SERVER = $_ENV = array();

$this->assertFalse(env('HTTPS'));

$_SERVER['HTTPS'] = 'on';
$this->assertTrue(env('HTTPS'));

$_SERVER['HTTPS'] = '1';
$this->assertTrue(env('HTTPS'));

$_SERVER['HTTPS'] = 'I am not empty';
$this->assertTrue(env('HTTPS'));

$_SERVER['HTTPS'] = 1;
$this->assertTrue(env('HTTPS'));

$_SERVER['HTTPS'] = 'off';
$this->assertFalse(env('HTTPS'));

$_SERVER['HTTPS'] = false;
$this->assertFalse(env('HTTPS'));

$_SERVER['HTTPS'] = '';
$this->assertFalse(env('HTTPS'));

$_SERVER = array();

Expand Down

0 comments on commit 7ca8510

Please sign in to comment.