Skip to content

Commit b94e9bb

Browse files
authored
Merge pull request #128 from ruudk/remove-ending-slash
AddPathPlugin > Trim ending slash on path
2 parents 5496bf2 + 6c5b5e6 commit b94e9bb

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Changed
66

77
- When multiple cookies exist, a single header with all cookies is sent as per RFC 6265 Section 5.4
8+
- AddPathPlugin will now trim of ending slashes in paths
89

910
## 1.8.1 - 2018-10-09
1011

spec/Plugin/AddPathPluginSpec.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,24 @@ function it_adds_path(
4646
$this->handleRequest($request, function () {}, function () {});
4747
}
4848

49-
function it_throws_exception_on_trailing_slash(UriInterface $host)
50-
{
49+
function it_removes_ending_slashes(
50+
RequestInterface $request,
51+
UriInterface $host,
52+
UriInterface $host2,
53+
UriInterface $uri
54+
) {
5155
$host->getPath()->shouldBeCalled()->willReturn('/api/');
56+
$host2->getPath()->shouldBeCalled()->willReturn('/api');
57+
$host->withPath('/api')->shouldBeCalled()->willReturn($host2);
58+
59+
$request->getUri()->shouldBeCalled()->willReturn($uri);
60+
$request->withUri($uri)->shouldBeCalled()->willReturn($request);
61+
62+
$uri->withPath('/api/users')->shouldBeCalled()->willReturn($uri);
63+
$uri->getPath()->shouldBeCalled()->willReturn('/users');
5264

5365
$this->beConstructedWith($host);
54-
$this->shouldThrow('\LogicException')->duringInstantiation();
66+
$this->handleRequest($request, function () {}, function () {});
5567
}
5668

5769
function it_throws_exception_on_empty_path(UriInterface $host)

src/Plugin/AddPathPlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(UriInterface $uri)
3535
}
3636

3737
if ('/' === substr($uri->getPath(), -1)) {
38-
throw new \LogicException('URI path cannot end with a slash.');
38+
$uri = $uri->withPath(rtrim($uri->getPath(), '/'));
3939
}
4040

4141
$this->uri = $uri;

0 commit comments

Comments
 (0)