Skip to content

Commit

Permalink
Merge pull request #8 from DFAU/fix/urldecode-resource-identifier
Browse files Browse the repository at this point in the history
fix: urldecode resourceIdentifier
  • Loading branch information
tmaroschik committed Dec 8, 2021
2 parents c20f540 + ccdce97 commit ec398c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Classes/Controller/JsonApiItemCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ public function read(ServerRequestInterface $request): ResponseInterface

$data = $this->fetchAndTransformData($request->getAttribute('variables')['id'], $request->getAttributes()['context']);

if (null === $data) {
return new JsonResponse($data, 404, ['Content-Type' => 'application/vnd.api+json; charset=utf-8']);
}

return new JsonResponse($data, 200, ['Content-Type' => 'application/vnd.api+json; charset=utf-8']);
}

protected function fetchAndTransformData(string $resourceIdentifier, ?Context $context = null): ?array
{
$resource = $this->repository->findOneByIdentifier($resourceIdentifier, $context);
$resource = $this->repository->findOneByIdentifier(\urldecode($resourceIdentifier), $context);

if (null === $resource) {
return null;
Expand Down
7 changes: 7 additions & 0 deletions Tests/Acceptance/Api/ReadItemCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ public function testReadItem(ApiTester $I): void
],
]);
}

public function testReadNotDefinedItem(ApiTester $I): void
{
$I->wantToBeBearerAuthenticated();
$I->sendGET('pages/1000');
$I->seeResponseCodeIs(HttpCode::NOT_FOUND);
}
}

0 comments on commit ec398c6

Please sign in to comment.