From 9b0761e1a2e0c37a32e841d8b1a6a60957916e81 Mon Sep 17 00:00:00 2001 From: pxpm Date: Fri, 4 Oct 2024 11:27:39 +0100 Subject: [PATCH 1/5] dont escape when dev error header is present --- src/app/Models/Traits/HasEnumFields.php | 2 +- src/resources/views/ui/errors/500.blade.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/Models/Traits/HasEnumFields.php b/src/app/Models/Traits/HasEnumFields.php index d3367f79cf..b4619dd1f9 100644 --- a/src/app/Models/Traits/HasEnumFields.php +++ b/src/app/Models/Traits/HasEnumFields.php @@ -27,7 +27,7 @@ public static function getPossibleEnumValues($field_name) $type = $connection->select($select)[0]->Type; } catch (\Exception $e) { - abort(500, 'Enum field type is not supported - it only works on MySQL. Please use select_from_array instead.'); + abort(500, 'Enum field type is not supported - it only works on MySQL. Please use select_from_array instead.', ['developer-error-exception']); } preg_match('/^enum\((.*)\)$/', $type, $matches); diff --git a/src/resources/views/ui/errors/500.blade.php b/src/resources/views/ui/errors/500.blade.php index bdc5fa562c..d84ad47c09 100644 --- a/src/resources/views/ui/errors/500.blade.php +++ b/src/resources/views/ui/errors/500.blade.php @@ -2,6 +2,7 @@ @php $error_number = 500; + $shouldEscape = ! in_array('developer-error-exception', $exception->getHeaders()); @endphp @section('title') @@ -9,5 +10,5 @@ @endsection @section('description') - {!! $exception?->getMessage() && config('app.debug') ? e($exception->getMessage()) : trans('backpack::base.error_page.message_500') !!} + {!! $exception?->getMessage() && config('app.debug') ? ($shouldEscape ? e($exception->getMessage()) : $exception->getMessage()) : trans('backpack::base.error_page.message_500') !!} @endsection From b95bf4f7b26d5efc8017f04531ededbab6c475f2 Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 7 Oct 2024 13:34:51 +0100 Subject: [PATCH 2/5] add developer error header for our abort functions --- .../Exceptions/BackpackProRequiredException.php | 2 +- src/app/Library/CrudPanel/CrudButton.php | 6 +++--- src/app/Library/CrudPanel/CrudColumn.php | 2 +- src/app/Library/CrudPanel/CrudField.php | 8 ++++---- src/app/Library/CrudPanel/CrudFilter.php | 2 +- src/app/Library/CrudPanel/Traits/Buttons.php | 4 ++-- src/app/Library/CrudPanel/Traits/Fields.php | 2 +- .../CrudPanel/Traits/FieldsProtectedMethods.php | 14 +++++++------- src/app/Library/CrudPanel/Traits/Filters.php | 6 +++--- src/app/Library/CrudPanel/Traits/Macroable.php | 2 +- src/app/Library/CrudPanel/Traits/Read.php | 2 +- src/app/Library/CrudPanel/Traits/Relationships.php | 2 +- src/app/Library/CrudPanel/Traits/SaveActions.php | 14 +++++++------- src/app/Library/CrudPanel/Traits/Search.php | 8 ++++---- src/app/Library/CrudPanel/Traits/Validation.php | 2 +- .../Uploaders/Support/RegisterUploadEvents.php | 2 +- src/app/Library/Widget.php | 2 +- src/helpers.php | 2 +- 18 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/app/Exceptions/BackpackProRequiredException.php b/src/app/Exceptions/BackpackProRequiredException.php index ff659e9e11..e9fefae220 100644 --- a/src/app/Exceptions/BackpackProRequiredException.php +++ b/src/app/Exceptions/BackpackProRequiredException.php @@ -20,6 +20,6 @@ public function render($request) break; } - return abort(500, $this->getMessage()); + return abort(500, $this->getMessage(), ['developer-error-exception']); } } diff --git a/src/app/Library/CrudPanel/CrudButton.php b/src/app/Library/CrudPanel/CrudButton.php index b0c1ac6f1f..e34bd0ca09 100644 --- a/src/app/Library/CrudPanel/CrudButton.php +++ b/src/app/Library/CrudPanel/CrudButton.php @@ -184,7 +184,7 @@ public function position($position) break; default: - abort(500, "Unknown button position - please use 'beginning' or 'end'."); + abort(500, "Unknown button position - please use 'beginning' or 'end'.", ['developer-error-exception']); } return $this; @@ -314,7 +314,7 @@ public function getHtml($entry = null) return view($button->getFinalViewPath(), compact('button', 'crud', 'entry')); } - abort(500, 'Unknown button type'); + abort(500, 'Unknown button type', ['developer-error-exception']); } /** @@ -342,7 +342,7 @@ private function getFinalViewPath() } } - abort(500, 'Button view and fallbacks do not exist for '.$this->name.' button.'); + abort(500, 'Button view and fallbacks do not exist for '.$this->name.' button.', ['developer-error-exception']); } /** diff --git a/src/app/Library/CrudPanel/CrudColumn.php b/src/app/Library/CrudPanel/CrudColumn.php index ea0c5e9747..6b209b0ae0 100644 --- a/src/app/Library/CrudPanel/CrudColumn.php +++ b/src/app/Library/CrudPanel/CrudColumn.php @@ -88,7 +88,7 @@ public static function name($name) public function key(string $key) { if (! isset($this->attributes['name'])) { - abort(500, 'Column name must be defined before changing the key.'); + abort(500, 'Column name must be defined before changing the key.', ['developer-error-exception']); } $columns = $this->crud()->columns(); diff --git a/src/app/Library/CrudPanel/CrudField.php b/src/app/Library/CrudPanel/CrudField.php index 76bc301a89..2877b79f7e 100644 --- a/src/app/Library/CrudPanel/CrudField.php +++ b/src/app/Library/CrudPanel/CrudField.php @@ -46,7 +46,7 @@ class CrudField public function __construct($nameOrDefinitionArray) { if (empty($nameOrDefinitionArray)) { - abort(500, 'Field name can\'t be empty.'); + abort(500, 'Field name can\'t be empty.', ['developer-error-exception']); } if (is_array($nameOrDefinitionArray)) { @@ -57,7 +57,7 @@ public function __construct($nameOrDefinitionArray) } if (is_array($name)) { - abort(500, 'Field name can\'t be an array. It should be a string. Error in field: '.json_encode($name)); + abort(500, 'Field name can\'t be an array. It should be a string. Error in field: '.json_encode($name), ['developer-error-exception']); } $field = $this->crud()->firstFieldWhere('name', $name); @@ -325,7 +325,7 @@ public function morphTypeField(array $configs) $morphField = $this->crud()->fields()[$this->attributes['name']]; if (empty($morphField) || ($morphField['relation_type'] ?? '') !== 'MorphTo') { - throw new \Exception('Trying to configure the morphType on a non-morphTo field. Check if field and relation name matches.'); + abort(500, 'Trying to configure the morphType on a non-morphTo field. Check if field and relation name matches.', ['developer-error-exception']); } [$morphTypeField, $morphIdField] = $morphField['subfields']; @@ -351,7 +351,7 @@ public function morphIdField(array $configs) $morphField = $this->crud()->fields()[$this->attributes['name']]; if (empty($morphField) || ($morphField['relation_type'] ?? '') !== 'MorphTo') { - throw new \Exception('Trying to configure the morphType on a non-morphTo field. Check if field and relation name matches.'); + abort(500, 'Trying to configure the morphType on a non-morphTo field. Check if field and relation name matches.', ['developer-error-exception']); } [$morphTypeField, $morphIdField] = $morphField['subfields']; diff --git a/src/app/Library/CrudPanel/CrudFilter.php b/src/app/Library/CrudPanel/CrudFilter.php index f722e7bc45..80fc526374 100644 --- a/src/app/Library/CrudPanel/CrudFilter.php +++ b/src/app/Library/CrudPanel/CrudFilter.php @@ -558,7 +558,7 @@ private function applyDefaultLogic($name, $operator, $input = null) break; default: - abort(500, 'Unknown filter operator.'); + abort(500, 'Unknown filter operator.', ['developer-error-exception']); break; } } diff --git a/src/app/Library/CrudPanel/Traits/Buttons.php b/src/app/Library/CrudPanel/Traits/Buttons.php index ceb8e2796e..12d8412d38 100644 --- a/src/app/Library/CrudPanel/Traits/Buttons.php +++ b/src/app/Library/CrudPanel/Traits/Buttons.php @@ -38,7 +38,7 @@ public function orderButtons(string $stack, array $order) // we parse the ordered buttons collect($order)->each(function ($btnKey) use ($newButtons, $stackButtons) { if (! $button = $stackButtons->where('name', $btnKey)->first()) { - abort(500, 'Button name [«'.$btnKey.'»] not found.'); + abort(500, 'Button name [«'.$btnKey.'»] not found.', ['developer-error-exception']); } $newButtons->push($button); }); @@ -117,7 +117,7 @@ public function modifyButton($name, $modifications = null) $button = $this->buttons()->firstWhere('name', $name); if (! $button) { - abort(500, 'CRUD Button "'.$name.'" not found. Please ensure the button exists before you modify it.'); + abort(500, 'CRUD Button "'.$name.'" not found. Please ensure the button exists before you modify it.', ['developer-error-exception']); } if (is_array($modifications)) { diff --git a/src/app/Library/CrudPanel/Traits/Fields.php b/src/app/Library/CrudPanel/Traits/Fields.php index 5c9ee075e2..ab851d9e25 100644 --- a/src/app/Library/CrudPanel/Traits/Fields.php +++ b/src/app/Library/CrudPanel/Traits/Fields.php @@ -475,7 +475,7 @@ public function getStrippedSaveRequest($request) if (is_string($setting) && class_exists($setting)) { $setting = new $setting(); - return is_callable($setting) ? $setting($request) : abort(500, get_class($setting).' is not invokable.'); + return is_callable($setting) ? $setting($request) : abort(500, get_class($setting).' is not invokable.', ['developer-error-exception']); } return $request->only($this->getAllFieldNames()); diff --git a/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php b/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php index fd1e17c9b9..a368de99ed 100644 --- a/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php +++ b/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php @@ -108,7 +108,7 @@ public function overwriteFieldNamesFromDotNotationToArray($fields) protected function makeSureFieldHasName($field) { if (empty($field)) { - abort(500, 'Field name can\'t be empty'); + abort(500, 'Field name can\'t be empty', ['developer-error-exception']); } if (is_string($field)) { @@ -116,11 +116,11 @@ protected function makeSureFieldHasName($field) } if (is_array($field) && ! isset($field['name'])) { - abort(500, 'All fields must have their name defined'); + abort(500, 'All fields must have their name defined', ['developer-error-exception']); } if (is_array($field['name'])) { - abort(500, 'Field name can\'t be an array. It should be a string. Error in field: '.json_encode($field['name'])); + abort(500, 'Field name can\'t be an array. It should be a string. Error in field: '.json_encode($field['name']), ['developer-error-exception']); } $field['name'] = Str::replace(' ', '', $field['name']); @@ -265,12 +265,12 @@ protected function makeSureSubfieldsHaveNecessaryAttributes($field) } if (! is_multidimensional_array($field['subfields'], true)) { - abort(500, 'Subfields of «'.$field['name'].'» are malformed. Make sure you provide an array of subfields.'); + abort(500, 'Subfields of «'.$field['name'].'» are malformed. Make sure you provide an array of subfields.', ['developer-error-exception']); } foreach ($field['subfields'] as $key => $subfield) { if (empty($subfield) || ! isset($subfield['name'])) { - abort(500, 'A subfield of «'.$field['name'].'» is malformed. Subfield attribute name can\'t be empty.'); + abort(500, 'A subfield of «'.$field['name'].'» is malformed. Subfield attribute name can\'t be empty.', ['developer-error-exception']); } // make sure the field definition is an array @@ -320,8 +320,8 @@ protected function makeSureSubfieldsHaveNecessaryAttributes($field) if ($field['allow_duplicate_pivots'] ?? false) { $pivotSelectorField['allow_duplicate_pivots'] = true; $field['subfields'] = Arr::prepend($field['subfields'], [ - 'name' => $field['pivot_key_name'] ?? 'id', - 'type' => 'hidden', + 'name' => $field['pivot_key_name'] ?? 'id', + 'type' => 'hidden', 'wrapper' => [ 'class' => 'd-none', ], diff --git a/src/app/Library/CrudPanel/Traits/Filters.php b/src/app/Library/CrudPanel/Traits/Filters.php index 0cf42b08b6..34f08d4457 100644 --- a/src/app/Library/CrudPanel/Traits/Filters.php +++ b/src/app/Library/CrudPanel/Traits/Filters.php @@ -73,11 +73,11 @@ protected function addFilterToCollection($options, $values = false, $filterLogic // check if another filter with the same name exists if (! isset($options['name'])) { - abort(500, 'All your filters need names.'); + abort(500, 'All your filters need names.', ['developer-error-exception']); } if ($this->filters()->contains('name', $options['name'])) { - abort(500, "Sorry, you can't have two filters with the same name."); + abort(500, "Sorry, you can't have two filters with the same name.", ['developer-error-exception']); } // add a new filter to the interface @@ -168,7 +168,7 @@ public function modifyFilter($name, $modifications) $filter = $this->filters()->firstWhere('name', $name); if (! $filter) { - abort(500, 'CRUD Filter "'.$name.'" not found. Please check the filter exists before you modify it.'); + abort(500, 'CRUD Filter "'.$name.'" not found. Please check the filter exists before you modify it.', ['developer-error-exception']); } if (is_array($modifications)) { diff --git a/src/app/Library/CrudPanel/Traits/Macroable.php b/src/app/Library/CrudPanel/Traits/Macroable.php index b26afcc555..565bba2136 100644 --- a/src/app/Library/CrudPanel/Traits/Macroable.php +++ b/src/app/Library/CrudPanel/Traits/Macroable.php @@ -21,7 +21,7 @@ trait Macroable public static function macro($name, $macro) { if (method_exists(new static(), $name)) { - abort(500, "Cannot register '$name' macro. '$name()' already exists on ".get_called_class()); + abort(500, "Cannot register '$name' macro. '$name()' already exists on ".get_called_class(), ['developer-error-exception']); } static::parentMacro($name, $macro); diff --git a/src/app/Library/CrudPanel/Traits/Read.php b/src/app/Library/CrudPanel/Traits/Read.php index 75af1708a8..301e5b387d 100644 --- a/src/app/Library/CrudPanel/Traits/Read.php +++ b/src/app/Library/CrudPanel/Traits/Read.php @@ -385,7 +385,7 @@ public function getPageLengthMenu() private function abortIfInvalidPageLength($value) { if ($value === 0 || (is_array($value) && in_array(0, $value))) { - abort(500, 'You should not use 0 as a key in paginator. If you are looking for "ALL" option, use -1 instead.'); + abort(500, 'You should not use 0 as a key in paginator. If you are looking for "ALL" option, use -1 instead.', ['developer-error-exception']); } } diff --git a/src/app/Library/CrudPanel/Traits/Relationships.php b/src/app/Library/CrudPanel/Traits/Relationships.php index 37db2b7cc2..5059ae8d45 100644 --- a/src/app/Library/CrudPanel/Traits/Relationships.php +++ b/src/app/Library/CrudPanel/Traits/Relationships.php @@ -33,7 +33,7 @@ public function getRelationInstance($field) return $relation; } - abort(500, 'Looks like field '.$field['name'].' is not properly defined. The '.$field['entity'].'() relationship doesn\'t seem to exist on the '.get_class($model).' model.'); + abort(500, 'Looks like field '.$field['name'].' is not properly defined. The '.$field['entity'].'() relationship doesn\'t seem to exist on the '.get_class($model).' model.', ['developer-error-exception']); } /** diff --git a/src/app/Library/CrudPanel/Traits/SaveActions.php b/src/app/Library/CrudPanel/Traits/SaveActions.php index d7d5fa759f..137535a502 100644 --- a/src/app/Library/CrudPanel/Traits/SaveActions.php +++ b/src/app/Library/CrudPanel/Traits/SaveActions.php @@ -80,7 +80,7 @@ public function addSaveAction(array $saveAction) { $orderCounter = $this->getOperationSetting('save_actions') !== null ? (count($this->getOperationSetting('save_actions')) + 1) : 1; //check for some mandatory fields - $saveAction['name'] ?? abort(500, 'Please define save action name.'); + $saveAction['name'] ?? abort(500, 'Please define save action name.', ['developer-error-exception']); $saveAction['redirect'] = $saveAction['redirect'] ?? fn ($crud, $request, $itemId) => $request->has('_http_referrer') ? $request->get('_http_referrer') : $crud->route; $saveAction['visible'] = $saveAction['visible'] ?? true; $saveAction['button_text'] = $saveAction['button_text'] ?? $saveAction['name']; @@ -291,7 +291,7 @@ public function getSaveAction() } return [ - 'active' => $saveCurrent, + 'active' => $saveCurrent, 'options' => $dropdownOptions, ]; } @@ -349,8 +349,8 @@ public function performSaveAction($itemId = null) // if the request is AJAX, return a JSON response if ($this->getRequest()->ajax()) { return response()->json([ - 'success' => true, - 'data' => $this->entry, + 'success' => true, + 'data' => $this->entry, 'redirect_url' => $redirectUrl, 'referrer_url' => $referrer_url ?? false, ]); @@ -372,7 +372,7 @@ public function setupDefaultSaveActions() { $defaultSaveActions = [ [ - 'name' => 'save_and_back', + 'name' => 'save_and_back', 'visible' => function ($crud) { return $crud->hasAccess('list'); }, @@ -382,7 +382,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_back'), ], [ - 'name' => 'save_and_edit', + 'name' => 'save_and_edit', 'visible' => function ($crud) { return $crud->hasAccess('update'); }, @@ -404,7 +404,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_edit'), ], [ - 'name' => 'save_and_new', + 'name' => 'save_and_new', 'visible' => function ($crud) { return $crud->hasAccess('create'); }, diff --git a/src/app/Library/CrudPanel/Traits/Search.php b/src/app/Library/CrudPanel/Traits/Search.php index 035cc3e776..fe63a0231b 100644 --- a/src/app/Library/CrudPanel/Traits/Search.php +++ b/src/app/Library/CrudPanel/Traits/Search.php @@ -25,7 +25,7 @@ public function applySearchTerm($searchTerm) return $this->query->where(function ($query) use ($searchTerm) { foreach ($this->columns() as $column) { if (! isset($column['type'])) { - abort(400, 'Missing column type when trying to apply search term.'); + abort(500, 'Missing column type when trying to apply search term.', ['developer-error-exception']); } $this->applySearchLogicForColumn($query, $column, $searchTerm); @@ -395,10 +395,10 @@ public function getEntriesAsJsonForDatatables($entries, $totalRows, $filteredRow } return [ - 'draw' => (isset($this->getRequest()['draw']) ? (int) $this->getRequest()['draw'] : 0), - 'recordsTotal' => $totalRows, + 'draw' => (isset($this->getRequest()['draw']) ? (int) $this->getRequest()['draw'] : 0), + 'recordsTotal' => $totalRows, 'recordsFiltered' => $filteredRows, - 'data' => $rows, + 'data' => $rows, ]; } diff --git a/src/app/Library/CrudPanel/Traits/Validation.php b/src/app/Library/CrudPanel/Traits/Validation.php index 9e710b8a73..23ca6091b4 100644 --- a/src/app/Library/CrudPanel/Traits/Validation.php +++ b/src/app/Library/CrudPanel/Traits/Validation.php @@ -73,7 +73,7 @@ public function setValidation($classOrRulesArray = false, $messages = [], $attri } elseif (is_string($classOrRulesArray) && class_exists($classOrRulesArray) && is_a($classOrRulesArray, FormRequest::class, true)) { $this->setValidationFromRequest($classOrRulesArray); } else { - abort(500, 'Please pass setValidation() nothing, a rules array or a FormRequest class.'); + abort(500, 'Please pass setValidation() nothing, a rules array or a FormRequest class.', ['developer-error-exception']); } } diff --git a/src/app/Library/Uploaders/Support/RegisterUploadEvents.php b/src/app/Library/Uploaders/Support/RegisterUploadEvents.php index 225a8a2ed6..237f90ce85 100644 --- a/src/app/Library/Uploaders/Support/RegisterUploadEvents.php +++ b/src/app/Library/Uploaders/Support/RegisterUploadEvents.php @@ -21,7 +21,7 @@ public function __construct( $this->crudObjectType = is_a($crudObject, CrudField::class) ? 'field' : (is_a($crudObject, CrudColumn::class) ? 'column' : null); if (! $this->crudObjectType) { - abort(500, 'Upload handlers only work for CrudField and CrudColumn classes.'); + abort(500, 'Upload handlers only work for CrudField and CrudColumn classes.', ['developer-error-exception']); } } diff --git a/src/app/Library/Widget.php b/src/app/Library/Widget.php index d6dd434230..3bd64f162b 100644 --- a/src/app/Library/Widget.php +++ b/src/app/Library/Widget.php @@ -172,7 +172,7 @@ public function getFinalViewPath() if (! backpack_pro()) { throw new BackpackProRequiredException('Cannot find the widget view: '.$this->attributes['type'].'. Please check for typos.'.(backpack_pro() ? '' : ' If you are trying to use a PRO widget, please first purchase and install the backpack/pro addon from backpackforlaravel.com'), 1); } - abort(500, 'Cannot find the view for «'.$this->attributes['type'].'» widget type. Please check for typos.'); + abort(500, 'Cannot find the view for «'.$this->attributes['type'].'» widget type. Please check for typos.', ['developer-error-exception']); } // ------- diff --git a/src/helpers.php b/src/helpers.php index 167611bf90..059e67c2b6 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -272,7 +272,7 @@ function backpack_view($view) return '- Called in: '.Str::after($functionFile, base_path()).' on line: '.$functionLine; })(); - abort(500, $errorMessage.$errorDetails); + abort(500, $errorMessage.$errorDetails, ['developer-error-exception']); } } From a9176826762babe630820924d19f6bf541113c0f Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 7 Oct 2024 13:36:17 +0100 Subject: [PATCH 3/5] add should escape to error pages --- src/resources/views/ui/errors/4xx.blade.php | 3 ++- src/resources/views/ui/errors/503.blade.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/resources/views/ui/errors/4xx.blade.php b/src/resources/views/ui/errors/4xx.blade.php index 305836f496..b524f82748 100644 --- a/src/resources/views/ui/errors/4xx.blade.php +++ b/src/resources/views/ui/errors/4xx.blade.php @@ -2,6 +2,7 @@ @php $error_number ??= 400; + $shouldEscape = ! in_array('developer-error-exception', $exception->getHeaders()); @endphp @section('title') @@ -9,7 +10,7 @@ @endsection @section('description') - {!! $exception?->getMessage() && config('app.debug') ? e($exception->getMessage()) : trans('backpack::base.error_page.message_4xx', [ + {!! $exception?->getMessage() && config('app.debug') ? ($shouldEscape ? e($exception->getMessage()) : $exception->getMessage()) : trans('backpack::base.error_page.message_4xx', [ 'href_back' => 'href="javascript:history.back()"', 'href_homepage' => 'href="'.url('').'"', ]) !!} diff --git a/src/resources/views/ui/errors/503.blade.php b/src/resources/views/ui/errors/503.blade.php index f9ef010db6..5d543e98b6 100644 --- a/src/resources/views/ui/errors/503.blade.php +++ b/src/resources/views/ui/errors/503.blade.php @@ -2,6 +2,7 @@ @php $error_number = 503; + $shouldEscape = ! in_array('developer-error-exception', $exception->getHeaders()); @endphp @section('title') @@ -9,5 +10,5 @@ @endsection @section('description') - {!! $exception?->getMessage() && config('app.debug') ? e($exception->getMessage()) : trans('backpack::base.error_page.message_503') !!} + {!! $exception?->getMessage() && config('app.debug') ? ($shouldEscape ? e($exception->getMessage()) : $exception->getMessage()) : trans('backpack::base.error_page.message_503') !!} @endsection From e6f1363eaad80867eb8140cfeee986bed383cba8 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 7 Oct 2024 12:36:37 +0000 Subject: [PATCH 4/5] Apply fixes from StyleCI [ci skip] [skip ci] --- .../CrudPanel/Traits/FieldsProtectedMethods.php | 4 ++-- src/app/Library/CrudPanel/Traits/SaveActions.php | 12 ++++++------ src/app/Library/CrudPanel/Traits/Search.php | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php b/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php index a368de99ed..c93e0fba4d 100644 --- a/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php +++ b/src/app/Library/CrudPanel/Traits/FieldsProtectedMethods.php @@ -320,8 +320,8 @@ protected function makeSureSubfieldsHaveNecessaryAttributes($field) if ($field['allow_duplicate_pivots'] ?? false) { $pivotSelectorField['allow_duplicate_pivots'] = true; $field['subfields'] = Arr::prepend($field['subfields'], [ - 'name' => $field['pivot_key_name'] ?? 'id', - 'type' => 'hidden', + 'name' => $field['pivot_key_name'] ?? 'id', + 'type' => 'hidden', 'wrapper' => [ 'class' => 'd-none', ], diff --git a/src/app/Library/CrudPanel/Traits/SaveActions.php b/src/app/Library/CrudPanel/Traits/SaveActions.php index 137535a502..91db553612 100644 --- a/src/app/Library/CrudPanel/Traits/SaveActions.php +++ b/src/app/Library/CrudPanel/Traits/SaveActions.php @@ -291,7 +291,7 @@ public function getSaveAction() } return [ - 'active' => $saveCurrent, + 'active' => $saveCurrent, 'options' => $dropdownOptions, ]; } @@ -349,8 +349,8 @@ public function performSaveAction($itemId = null) // if the request is AJAX, return a JSON response if ($this->getRequest()->ajax()) { return response()->json([ - 'success' => true, - 'data' => $this->entry, + 'success' => true, + 'data' => $this->entry, 'redirect_url' => $redirectUrl, 'referrer_url' => $referrer_url ?? false, ]); @@ -372,7 +372,7 @@ public function setupDefaultSaveActions() { $defaultSaveActions = [ [ - 'name' => 'save_and_back', + 'name' => 'save_and_back', 'visible' => function ($crud) { return $crud->hasAccess('list'); }, @@ -382,7 +382,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_back'), ], [ - 'name' => 'save_and_edit', + 'name' => 'save_and_edit', 'visible' => function ($crud) { return $crud->hasAccess('update'); }, @@ -404,7 +404,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_edit'), ], [ - 'name' => 'save_and_new', + 'name' => 'save_and_new', 'visible' => function ($crud) { return $crud->hasAccess('create'); }, diff --git a/src/app/Library/CrudPanel/Traits/Search.php b/src/app/Library/CrudPanel/Traits/Search.php index fe63a0231b..04c807ea59 100644 --- a/src/app/Library/CrudPanel/Traits/Search.php +++ b/src/app/Library/CrudPanel/Traits/Search.php @@ -395,10 +395,10 @@ public function getEntriesAsJsonForDatatables($entries, $totalRows, $filteredRow } return [ - 'draw' => (isset($this->getRequest()['draw']) ? (int) $this->getRequest()['draw'] : 0), - 'recordsTotal' => $totalRows, + 'draw' => (isset($this->getRequest()['draw']) ? (int) $this->getRequest()['draw'] : 0), + 'recordsTotal' => $totalRows, 'recordsFiltered' => $filteredRows, - 'data' => $rows, + 'data' => $rows, ]; } From 55cdcc03600b0e29366bd03f28fad60b7db96313 Mon Sep 17 00:00:00 2001 From: pxpm Date: Tue, 8 Oct 2024 10:39:20 +0100 Subject: [PATCH 5/5] fix tests --- tests/Unit/CrudPanel/CrudPanelButtonsTest.php | 2 +- tests/Unit/CrudPanel/CrudPanelFieldsTest.php | 4 ++-- tests/Unit/CrudPanel/CrudPanelMacroTest.php | 2 +- tests/Unit/CrudPanel/CrudPanelValidationTest.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Unit/CrudPanel/CrudPanelButtonsTest.php b/tests/Unit/CrudPanel/CrudPanelButtonsTest.php index 20f9486e77..6408d16d00 100644 --- a/tests/Unit/CrudPanel/CrudPanelButtonsTest.php +++ b/tests/Unit/CrudPanel/CrudPanelButtonsTest.php @@ -362,7 +362,7 @@ public function testThrowsErrorInUnknownPosition() } catch (\Throwable $e) { } $this->assertEquals( - new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Unknown button position - please use \'beginning\' or \'end\'.'), + new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Unknown button position - please use \'beginning\' or \'end\'.', null, ['developer-error-exception']), $e ); } diff --git a/tests/Unit/CrudPanel/CrudPanelFieldsTest.php b/tests/Unit/CrudPanel/CrudPanelFieldsTest.php index 973bcaab59..be6ac8af6e 100644 --- a/tests/Unit/CrudPanel/CrudPanelFieldsTest.php +++ b/tests/Unit/CrudPanel/CrudPanelFieldsTest.php @@ -658,7 +658,7 @@ public function testItAbortsOnUnexpectedEntity() } catch (\Throwable $e) { } $this->assertEquals( - new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Looks like field doesNotExist is not properly defined. The doesNotExist() relationship doesn\'t seem to exist on the Backpack\CRUD\Tests\Config\Models\TestModel model.'), + new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Looks like field doesNotExist is not properly defined. The doesNotExist() relationship doesn\'t seem to exist on the Backpack\CRUD\Tests\Config\Models\TestModel model.', null, ['developer-error-exception']), $e ); } @@ -903,7 +903,7 @@ public function testItAbortsWithEmptyNamesFluently() } catch (\Throwable $e) { } $this->assertEquals( - new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Field name can\'t be empty.'), + new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Field name can\'t be empty.', null, ['developer-error-exception']), $e ); } diff --git a/tests/Unit/CrudPanel/CrudPanelMacroTest.php b/tests/Unit/CrudPanel/CrudPanelMacroTest.php index 12287ae90c..e19d165917 100644 --- a/tests/Unit/CrudPanel/CrudPanelMacroTest.php +++ b/tests/Unit/CrudPanel/CrudPanelMacroTest.php @@ -27,7 +27,7 @@ public function testThrowsErrorIfMacroExists() } catch (\Throwable $e) { } $this->assertEquals( - new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Cannot register \'setModel\' macro. \'setModel()\' already exists on Backpack\CRUD\app\Library\CrudPanel\CrudPanel'), + new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Cannot register \'setModel\' macro. \'setModel()\' already exists on Backpack\CRUD\app\Library\CrudPanel\CrudPanel', null, ['developer-error-exception']), $e ); } diff --git a/tests/Unit/CrudPanel/CrudPanelValidationTest.php b/tests/Unit/CrudPanel/CrudPanelValidationTest.php index ef10694048..89503025e2 100644 --- a/tests/Unit/CrudPanel/CrudPanelValidationTest.php +++ b/tests/Unit/CrudPanel/CrudPanelValidationTest.php @@ -203,7 +203,7 @@ public function testItThrowsExceptionWithInvalidValidationClass() } catch (\Throwable $e) { } $this->assertEquals( - new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Please pass setValidation() nothing, a rules array or a FormRequest class.'), + new \Symfony\Component\HttpKernel\Exception\HttpException(500, 'Please pass setValidation() nothing, a rules array or a FormRequest class.', null, ['developer-error-exception']), $e ); }