Skip to content

Commit 8855bf7

Browse files
committed
fix: wrong resource iri
1 parent 66a49fd commit 8855bf7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

features/main/standard_put.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ Feature: Spec-compliant PUT support
6666
"""
6767
Then the response status code should be 400
6868

69+
Scenario: Fails to create a new resource when the JSON-LD @id doesn't match the URI
70+
When I add "Content-Type" header equal to "application/ld+json"
71+
And I send a "PUT" request to "/standard_puts/7" with body:
72+
"""
73+
{
74+
"@id": "/standard_puts/6",
75+
"@context": "/contexts/StandardPut",
76+
"@type": "StandardPut",
77+
"foo": "a",
78+
"bar": "b"
79+
}
80+
"""
81+
Then the response status code should be 400
82+
6983
Scenario: Replace an existing resource
7084
When I add "Content-Type" header equal to "application/ld+json"
7185
And I send a "PUT" request to "/standard_puts/5" with body:

src/Symfony/Routing/IriConverter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
7878
throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
7979
}
8080

81+
foreach ($context['uri_variables'] ?? [] as $key => $value) {
82+
if (!isset($parameters[$key]) || $parameters[$key] !== (string) $value) {
83+
throw new InvalidArgumentException(sprintf('The iri "%s" does not reference the correct resource.', $iri));
84+
}
85+
}
86+
8187
if ($operation && $operation->getClass() !== $parameters['_api_resource_class']) {
8288
throw new InvalidArgumentException(sprintf('The iri "%s" does not reference the correct resource.', $iri));
8389
}

0 commit comments

Comments
 (0)