Skip to content

Commit 05ee35c

Browse files
committed
validate if length is on the allowed values
1 parent c4235d3 commit 05ee35c

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/app/Http/Controllers/Operations/ListOperation.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ public function search()
7979
$length = (int) request()->input('length');
8080
$search = request()->input('search');
8181

82-
// we get the max length from the page length menu possibilities
83-
$maxLength = $this->crud->maxPageLength();
84-
85-
$length = $maxLength === -1 ? $length : ($length > $maxLength ? $maxLength : $length);
82+
// check if length is allowed by developer
83+
if ($length && ! in_array($length, $this->crud->getPageLengthMenu()[0])) {
84+
return response()->json([
85+
'error' => 'Unknown page length.',
86+
], 400);
87+
}
8688

8789
// if a search term was present
8890
if ($search && $search['value'] ?? false) {

src/app/Library/CrudPanel/Traits/Read.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,6 @@ public function getDefaultPageLength()
218218
return $this->getOperationSetting('defaultPageLength') ?? config('backpack.crud.operations.list.defaultPageLength') ?? 25;
219219
}
220220

221-
/**
222-
* Get the higher limit from the page length menu.
223-
* -1 means "All" so if present it means no limit.
224-
*/
225-
public function maxPageLength(): int
226-
{
227-
$pageLengthMenu = $this->getPageLengthMenu();
228-
229-
if (in_array(-1, $pageLengthMenu[0])) {
230-
return -1;
231-
}
232-
233-
return (int) max($pageLengthMenu[0]);
234-
}
235-
236221
/**
237222
* If a custom page length was specified as default, make sure it
238223
* also show up in the page length menu.

0 commit comments

Comments
 (0)