浏览代码

merged branch cs278/issue/2394 (PR #2394)

Commits
-------

d8dfca2 [BrowserKit] Added additional unit tests for capital letters in cookies
00cbd39 [BrowserKit] Fixed cookie expiry discard when attribute contains capitals

Discussion
----------

[BrowserKit] Cookie expiry is discared if the attribute name contains a capital letter

`Cookie::fromString()` discards the expiry time of a cookie where the `expires` attribute contains a capital letter, like `foo=bar; Expires=Fri, 31 Dec 2010 23:59:59 GMT`.

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Fabien Potencier 13 年之前
父节点
当前提交
663e25af64

+ 1 - 1
src/Symfony/Component/BrowserKit/Cookie.php

@@ -169,7 +169,7 @@ class Cookie
             }
 
             if (2 === count($elements = explode('=', $part, 2))) {
-                if ('expires' === $elements[0]) {
+                if ('expires' === strtolower($elements[0])) {
                     $elements[1] = self::parseDate($elements[1]);
                 }
 

+ 7 - 0
tests/Symfony/Tests/Component/BrowserKit/CookieTest.php

@@ -61,6 +61,13 @@ class CookieTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testFromStringWithCapitalization()
+    {
+        $this->assertEquals('Foo=Bar', (string) Cookie::fromString('Foo=Bar'));
+        $this->assertEquals('foo=bar; expires=Fri, 31 Dec 2010 23:59:59 GMT', (string) Cookie::fromString('foo=bar; Expires=Fri, 31 Dec 2010 23:59:59 GMT'));
+        $this->assertEquals('foo=bar; domain=www.example.org; httponly', (string) Cookie::fromString('foo=bar; DOMAIN=www.example.org; HttpOnly'));
+    }
+
     public function testFromStringWithUrl()
     {
         $this->assertEquals('foo=bar; domain=www.example.com', (string) Cookie::FromString('foo=bar', 'http://www.example.com/'));