Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle rules with ;; separator correctly #4945

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pterodactyl\Http\Controllers\Api\Client\Servers;

use Illuminate\Support\Str;
use Pterodactyl\Models\Server;
use Pterodactyl\Facades\Activity;
use Pterodactyl\Services\Servers\StartupCommandService;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function update(UpdateStartupVariableRequest $request, Server $server): a
}

// Revalidate the variable value using the egg variable specific validation rules for it.
$this->validate($request, ['value' => $variable->rules]);
$this->validate($request, ['value' => Str::contains($variable->rules, ';;') ? explode(';;', $variable->rules) : $variable->rules]);

$this->repository->updateOrCreate([
'server_id' => $server->id,
Expand Down
7 changes: 6 additions & 1 deletion app/Services/Eggs/Variables/VariableCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pterodactyl\Services\Eggs\Variables;

use Illuminate\Support\Str;
use Pterodactyl\Models\EggVariable;
use Pterodactyl\Traits\Services\ValidatesValidationRules;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
Expand Down Expand Up @@ -42,7 +43,11 @@ public function handle(int $egg, array $data): EggVariable
}

if (!empty($data['rules'] ?? '')) {
$this->validateRules($data['rules']);
$this->validateRules(
(is_string($data['rules']) && Str::contains($data['rules'], ';;'))
? explode(';;', $data['rules'])
: $data['rules']
);
}

$options = array_get($data, 'options') ?? [];
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Servers/VariableValidatorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Pterodactyl\Services\Servers;

use Illuminate\Support\Str;
use Pterodactyl\Models\User;
use Illuminate\Support\Collection;
use Pterodactyl\Models\EggVariable;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function handle(int $egg, array $fields = []): Collection
$data = $rules = $customAttributes = [];
foreach ($variables as $variable) {
$data['environment'][$variable->env_variable] = array_get($fields, $variable->env_variable);
$rules['environment.' . $variable->env_variable] = $variable->rules;
$rules['environment.' . $variable->env_variable] = Str::contains($variable->rules, ';;') ? explode(';;', $variable->rules) : $variable->rules;
$customAttributes['environment.' . $variable->env_variable] = trans('validation.internal.variable_value', ['env' => $variable->name]);
}

Expand Down
2 changes: 1 addition & 1 deletion resources/scripts/api/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ export const rawDataToServerEggVariable = ({ attributes }: FractalResponseData):
defaultValue: attributes.default_value,
serverValue: attributes.server_value,
isEditable: attributes.is_editable,
rules: attributes.rules.split('|'),
rules: attributes.rules.includes(';;') ? attributes.rules.split(';;') : attributes.rules.split('|'),
});
Loading