浏览代码

[BrowserKit] standardized cookie paths (an empty path is equivalent to /)

Fabien Potencier 13 年之前
父节点
当前提交
128468193f

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

@@ -67,7 +67,7 @@ class Cookie
         }
         $this->name     = $name;
         $this->expires  = null === $expires ? null : (integer) $expires;
-        $this->path     = empty($path) ? null : $path;
+        $this->path     = empty($path) ? '/' : $path;
         $this->domain   = $domain;
         $this->secure   = (Boolean) $secure;
         $this->httponly = (Boolean) $httponly;
@@ -92,7 +92,7 @@ class Cookie
             $cookie .= '; domain='.$this->domain;
         }
 
-        if (null !== $this->path) {
+        if ('/' !== $this->path) {
             $cookie .= '; path='.$this->path;
         }
 
@@ -130,8 +130,8 @@ class Cookie
         $values = array(
             'name'     => trim($name),
             'value'    => trim($value),
-            'expires'  =>  null,
-            'path'     => null,
+            'expires'  => null,
+            'path'     => '/',
             'domain'   => '',
             'secure'   => false,
             'httponly' => false,
@@ -262,7 +262,7 @@ class Cookie
      */
     public function getPath()
     {
-        return null !== $this->path ? $this->path : '/';
+        return $this->path;
     }
 
     /**

+ 1 - 1
tests/Symfony/Tests/Component/BrowserKit/CookieTest.php

@@ -65,7 +65,7 @@ class CookieTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals('foo=bar; domain=www.example.com', (string) Cookie::FromString('foo=bar', 'http://www.example.com/'));
         $this->assertEquals('foo=bar; domain=www.example.com; path=/foo', (string) Cookie::FromString('foo=bar', 'http://www.example.com/foo/bar'));
-        $this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
+        $this->assertEquals('foo=bar; domain=www.example.com', (string) Cookie::FromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
         $this->assertEquals('foo=bar; domain=www.myotherexample.com', (string) Cookie::FromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));
     }