Skip to content

Cookie for root path (/) matches only exact match. #65

Closed
@Maff-

Description

@Maff-
Q A
Bug? yes
New Feature? no
Version v1.4.0

Actual Behavior

When having a Cookie with the path set to the domain root (e.g. /), and checking to see if another path matches (i.e. /cookies) it will always fail. (Except when checking an exact match, /).

Expected Behavior

I expect path /cookies to match a Cookie with path /.

Steps to Reproduce

$cookie = new Cookie('foo', 'bar', null, 'example.com', '/');
var_dump($cookie->matchPath('/cookies')); // = false, but should be true
// spec\Http\Message\CookieSpec
function it_matches_the_root_path()
{
    $this->beConstructedWith('name', 'value', null, null, '/');
    $this->matchPath('/')->shouldReturn(true);
    // we should add this line below
    $this->matchPath('/cookies')->shouldReturn(true);
}

Possible Solutions

A solution shouldn't be to hard to find. My guess is that adding a trailing slash isn't completely correct, but reading the linked rfc section doesn't make things easier. 😕

current code. not a solution!:

/**
 * Checks whether this cookie is meant for this path.
 * @see http://tools.ietf.org/html/rfc6265#section-5.1.4
 */
public function matchPath($path)
{
    return $this->path === $path || (strpos($path, $this->path.'/') === 0);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions