Skip to content

Commit 5fd6c76

Browse files
Maff-sagikazarmark
authored andcommitted
Fix cookie root path match for subdirectories. Refs #65
1 parent 20ffbdc commit 5fd6c76

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
4+
## Unreleased
5+
6+
### Fixed
7+
8+
- Cookie::matchPath Cookie with root path (`/`) will not match sub path (e.g. `/cookie`).
9+
10+
311
## 1.4.0 - 2016-10-20
412

513
### Added

spec/CookieSpec.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ function it_matches_a_path()
189189
$this->beConstructedWith('name', 'value', null, null, '/path/to/somewhere');
190190

191191
$this->matchPath('/path/to/somewhere')->shouldReturn(true);
192+
$this->matchPath('/path/to/somewhere/else')->shouldReturn(true);
192193
$this->matchPath('/path/to/somewhereelse')->shouldReturn(false);
193194
}
194195

@@ -197,6 +198,8 @@ function it_matches_the_root_path()
197198
$this->beConstructedWith('name', 'value', null, null, '/');
198199

199200
$this->matchPath('/')->shouldReturn(true);
201+
$this->matchPath('/cookies')->shouldReturn(true);
202+
$this->matchPath('/cookies/')->shouldReturn(true);
200203
}
201204

202205
function it_is_secure()

src/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function withPath($path)
313313
*/
314314
public function matchPath($path)
315315
{
316-
return $this->path === $path || (strpos($path, $this->path.'/') === 0);
316+
return $this->path === $path || (strpos($path, rtrim($this->path, '/').'/') === 0);
317317
}
318318

319319
/**

0 commit comments

Comments
 (0)