Skip to content

Commit

Permalink
[BUGFIX] - Partial-Data; Fixed correct handling of header data
Browse files Browse the repository at this point in the history
[BUGFIX] - Partial-Data; check component for valid partial request
  • Loading branch information
fduarte42 committed Aug 15, 2023
1 parent 8c17532 commit 010f0b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Service/Inertia.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function render(string $component, array $props = []): ResponseInterface
->withUrl((string)$this->request->getUri());

if ($this->request->hasHeader('X-Inertia-Partial-Data')) {
$only = $this->request->getHeader('X-Inertia-Partial-Data');
$props = ($only && $this->request->getHeaderLine('X-Inertia-Partial-Component'))
$only = explode(',', $this->request->getHeaderLine('X-Inertia-Partial-Data'));
$props = ($only && $this->request->getHeaderLine('X-Inertia-Partial-Component') === $component)
? array_intersect_key($props, array_flip((array) $only))
: $props;
}
Expand Down
10 changes: 4 additions & 6 deletions test/Service/InertiaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ public function testRenderReturnPartialDataWhenHeaderContainsPartialData()
$request = $this->prophesize(ServerRequestInterface::class);
$request->hasHeader('X-Inertia')->willReturn(true);
$request->hasHeader('X-Inertia-Partial-Data')->willReturn(true);
$request->getHeaderLine('X-Inertia-Partial-Component')->willReturn(Argument::type('string'));
$request->getHeader('X-Inertia-Partial-Data')->willReturn([
'key2'
]);
$json = '{"component":"type(string)","props":{"key2":"value2"},"url":"callback()","version":null}';
$request->getHeaderLine('X-Inertia-Partial-Component')->willReturn('component');
$request->getHeaderLine('X-Inertia-Partial-Data')->willReturn('key2');
$json = '{"component":"component","props":{"key2":"value2"},"url":"callback()","version":null}';
$jsonResponse = null;

$uri = $this->prophesize(UriInterface::class);
Expand Down Expand Up @@ -133,7 +131,7 @@ public function testRenderReturnPartialDataWhenHeaderContainsPartialData()
);

$returnedResponse = $inertia->render(
Argument::type('string'),
'component',
[
'key1' => fn() => 'value1',
'key2' => fn() => 'value2'
Expand Down

0 comments on commit 010f0b9

Please sign in to comment.