Browse Source

Merge pull request #11126 from cakephp/issue-11120

Add casting to make CookieComponent more backwards compatible.
Mark Story 8 years ago
parent
commit
8e2f1f9dfb

+ 2 - 2
src/Controller/Component/CookieComponent.php

@@ -316,8 +316,8 @@ class CookieComponent extends Component
             'expire' => $expires->format('U'),
             'path' => $config['path'],
             'domain' => $config['domain'],
-            'secure' => $config['secure'],
-            'httpOnly' => $config['httpOnly']
+            'secure' => (bool)$config['secure'],
+            'httpOnly' => (bool)$config['httpOnly']
         ]);
     }
 

+ 19 - 0
tests/TestCase/Controller/Component/CookieComponentTest.php

@@ -106,6 +106,25 @@ class CookieComponentTest extends TestCase
     }
 
     /**
+     * Test backwards compatibility with settings that use type juggling.
+     *
+     * @return void
+     */
+    public function testSettingsCompatibility()
+    {
+        $this->Cookie->config([
+            'expires' => '+10 seconds',
+            'path' => '/',
+            'domain' => '',
+            'secure' => 0,
+            'key' => 'somerandomhaskeysomerandomhaskey',
+            'encryption' => 0,
+        ]);
+        $this->Cookie->write('key', 'value');
+        $this->assertSame('value', $this->Cookie->read('key'));
+    }
+
+    /**
      * sets up some default cookie data.
      *
      * @return void