diff --git a/cake/basics.php b/cake/basics.php index aaf1124d4..1c1dd61d1 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -362,8 +362,8 @@ if (!function_exists('array_combine')) { */ 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); } diff --git a/cake/tests/cases/basics.test.php b/cake/tests/cases/basics.test.php index 0f81ab27f..a320bc075 100644 --- a/cake/tests/cases/basics.test.php +++ b/cake/tests/cases/basics.test.php @@ -94,11 +94,28 @@ class BasicsTest extends CakeTestCase { $_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();