Skip to content

Commit 39f74f2

Browse files
authored
Merge pull request #2298 from Simperfit/bugfix/do-not-throw-on-matching-something-that-looks-like-an-url
bugfix: throw InvalidArgument on matching something that looks like an url
2 parents 9afd2d3 + ae7aa97 commit 39f74f2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

features/main/crud.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ Feature: Create-Retrieve-Update-Delete
476476
{
477477
"@id": "/dummies/1",
478478
"name": "A nice dummy",
479+
"dummyDate": "2018-12-01 13:12",
479480
"jsonData": [{
480481
"key": "value1"
481482
},
@@ -498,7 +499,7 @@ Feature: Create-Retrieve-Update-Delete
498499
"description": null,
499500
"dummy": null,
500501
"dummyBoolean": null,
501-
"dummyDate": "2015-03-01T10:00:00+00:00",
502+
"dummyDate": "2018-12-01T13:12:00+00:00",
502503
"dummyFloat": null,
503504
"dummyPrice": null,
504505
"relatedDummy": null,
@@ -538,7 +539,7 @@ Feature: Create-Retrieve-Update-Delete
538539
"description": null,
539540
"dummy": null,
540541
"dummyBoolean": null,
541-
"dummyDate": "2015-03-01T10:00:00+00:00",
542+
"dummyDate": "2018-12-01T13:12:00+00:00",
542543
"dummyFloat": null,
543544
"dummyPrice": null,
544545
"relatedDummy": null,

src/Bridge/Symfony/Routing/IriConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
3131
use ApiPlatform\Core\Util\AttributesExtractor;
3232
use ApiPlatform\Core\Util\ClassInfoTrait;
33+
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
3334
use Symfony\Component\PropertyAccess\PropertyAccess;
3435
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
3536
use Symfony\Component\Routing\Exception\ExceptionInterface as RoutingExceptionInterface;
@@ -73,6 +74,8 @@ public function getItemFromIri(string $iri, array $context = [])
7374
$parameters = $this->router->match($iri);
7475
} catch (RoutingExceptionInterface $e) {
7576
throw new InvalidArgumentException(sprintf('No route matches "%s".', $iri), $e->getCode(), $e);
77+
} catch (RequestExceptionInterface $e) {
78+
throw new InvalidArgumentException(sprintf('No route matches "%s".', $iri), $e->getCode(), $e);
7679
}
7780

7881
if (!isset($parameters['_api_resource_class'])) {

tests/Bridge/Symfony/Routing/IriConverterTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
3232
use PHPUnit\Framework\TestCase;
3333
use Prophecy\Argument;
34+
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
3435
use Symfony\Component\Routing\Exception\RouteNotFoundException;
3536
use Symfony\Component\Routing\RouterInterface;
3637

@@ -98,6 +99,20 @@ public function testGetItemFromIriItemNotFoundException()
9899
$converter->getItemFromIri('/users/3');
99100
}
100101

102+
public function testGetItemFromIriWithDateLooksLikeUrl()
103+
{
104+
$this->expectException(InvalidArgumentException::class);
105+
$this->expectExceptionMessage('No route matches "28-01-2018 10:10".');
106+
107+
$itemDataProviderProphecy = $this->prophesize(ItemDataProviderInterface::class);
108+
109+
$routerProphecy = $this->prophesize(RouterInterface::class);
110+
$routerProphecy->match('28-01-2018 10:10')->willThrow(new SuspiciousOperationException())->shouldBeCalledTimes(1);
111+
112+
$converter = $this->getIriConverter($routerProphecy, null, $itemDataProviderProphecy);
113+
$converter->getItemFromIri('28-01-2018 10:10');
114+
}
115+
101116
public function testGetItemFromIri()
102117
{
103118
$item = new \stdClass();

0 commit comments

Comments
 (0)