From 2212f28351b24e3e756426eddcf6c7f6e58d5684 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 21 Jan 2018 11:58:59 -0600 Subject: [PATCH] Don't break the page if no variable rules are provided. --- CHANGELOG.md | 1 + .../Admin/Egg/EggVariableFormRequest.php | 18 ++++++++++-------- .../pterodactyl/admin/eggs/variables.blade.php | 14 +++++++------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed15d3c04..e258be272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### v0.7.0-beta.5 (Derelict Dermodactylus) ### Fixed * `[beta.4]` — Fixes some bad search and replace action that happened previously and was throwing errors when validating user permissions. +* `[beta.4]` — Fixes behavior of variable validation to not break the page when no rules are provided. ## v0.7.0-beta.4 (Derelict Dermodactylus) ### Fixed diff --git a/app/Http/Requests/Admin/Egg/EggVariableFormRequest.php b/app/Http/Requests/Admin/Egg/EggVariableFormRequest.php index 621fbd772..f39cdd00c 100644 --- a/app/Http/Requests/Admin/Egg/EggVariableFormRequest.php +++ b/app/Http/Requests/Admin/Egg/EggVariableFormRequest.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Http\Requests\Admin\Egg; @@ -15,6 +8,8 @@ use Pterodactyl\Http\Requests\Admin\AdminFormRequest; class EggVariableFormRequest extends AdminFormRequest { /** + * Define rules for validation of this request. + * * @return array */ public function rules() @@ -23,7 +18,7 @@ class EggVariableFormRequest extends AdminFormRequest 'name' => 'required|string|min:1|max:255', 'description' => 'sometimes|nullable|string', 'env_variable' => 'required|regex:/^[\w]{1,255}$/|notIn:' . EggVariable::RESERVED_ENV_NAMES, - 'default_value' => 'string', + 'default_value' => 'nullable|string', 'options' => 'sometimes|required|array', 'rules' => 'bail|required|string', ]; @@ -41,6 +36,13 @@ class EggVariableFormRequest extends AdminFormRequest $rules = $this->input('rules', $this->route()->parameter('egg')->rules); } + // If rules is not a string it is already violating the rule defined above + // so just skip the addition of default value rules since this request + // will fail anyways. + if (! is_string($rules)) { + return; + } + $validator->addRules(['default_value' => $rules]); } } diff --git a/resources/themes/pterodactyl/admin/eggs/variables.blade.php b/resources/themes/pterodactyl/admin/eggs/variables.blade.php index 5ceeda675..bd18e05cf 100644 --- a/resources/themes/pterodactyl/admin/eggs/variables.blade.php +++ b/resources/themes/pterodactyl/admin/eggs/variables.blade.php @@ -99,25 +99,25 @@