Skip to content

Commit 4215a07

Browse files
committed
[Bugfix] Ensure empty sort and include params pass validation
Closes #518
1 parent 744d4e0 commit 4215a07

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ All notable changes to this project will be documented in this file. This projec
1212
Resolve model bindings correctly when substituting URL parameters.
1313
- Updated type-hinting for `Responses::errros()` method and allowed a `null` default
1414
status code to be passed to `Helpers::httpErrorStatus()` method.
15+
- [#518](https://github.com/cloudcreativity/laravel-json-api/issues/518)
16+
Ensure empty `sort` and `include` query parameters pass validation.
1517

1618
## [2.0.0-beta.3] - 2020-04-13
1719

src/Validation/AbstractValidators.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ protected function defaultQueryRules(): array
655655
],
656656
'include' => [
657657
'bail',
658+
'nullable',
658659
'string',
659660
$this->allowedIncludePaths(),
660661
],
@@ -665,6 +666,7 @@ protected function defaultQueryRules(): array
665666
],
666667
'sort' => [
667668
'bail',
669+
'nullable',
668670
'string',
669671
$this->allowedSortParameters(),
670672
],

tests/lib/Integration/Eloquent/ResourceTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public function testSortedSearch()
6767
->assertFetchedManyInOrder([$b, $a]);
6868
}
6969

70+
public function testEmptySort(): void
71+
{
72+
$posts = factory(Post::class, 2)->create();
73+
74+
$this->jsonApi()
75+
->get('api/v1/posts?sort=')
76+
->assertFetchedMany($posts);
77+
}
78+
7079
public function testFilteredSearch()
7180
{
7281
$a = factory(Post::class)->create([
@@ -329,6 +338,18 @@ public function testReadWithInclude()
329338
->assertIsIncluded('tags', $tag);
330339
}
331340

341+
/**
342+
* @see https://github.com/cloudcreativity/laravel-json-api/issues/518
343+
*/
344+
public function testReadWithEmptyInclude(): void
345+
{
346+
$post = factory(Post::class)->create();
347+
348+
$this->jsonApi()
349+
->get("api/v1/posts/{$post->getRouteKey()}?include=")
350+
->assertFetchedOne($this->serialize($post));
351+
}
352+
332353
/**
333354
* @see https://github.com/cloudcreativity/laravel-json-api/issues/194
334355
*/

0 commit comments

Comments
 (0)