Skip to content

AddPathPlugin > Trim ending slash on path #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

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

## 1.8.1 - 2018-10-09

Expand Down
18 changes: 15 additions & 3 deletions spec/Plugin/AddPathPluginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ function it_adds_path(
$this->handleRequest($request, function () {}, function () {});
}

function it_throws_exception_on_trailing_slash(UriInterface $host)
{
function it_removes_ending_slashes(
RequestInterface $request,
UriInterface $host,
UriInterface $host2,
UriInterface $uri
) {
$host->getPath()->shouldBeCalled()->willReturn('/api/');
$host2->getPath()->shouldBeCalled()->willReturn('/api');
$host->withPath('/api')->shouldBeCalled()->willReturn($host2);

$request->getUri()->shouldBeCalled()->willReturn($uri);
$request->withUri($uri)->shouldBeCalled()->willReturn($request);

$uri->withPath('/api/users')->shouldBeCalled()->willReturn($uri);
$uri->getPath()->shouldBeCalled()->willReturn('/users');

$this->beConstructedWith($host);
$this->shouldThrow('\LogicException')->duringInstantiation();
$this->handleRequest($request, function () {}, function () {});
}

function it_throws_exception_on_empty_path(UriInterface $host)
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/AddPathPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(UriInterface $uri)
}

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

$this->uri = $uri;
Expand Down