From b6a4c7383a1510a144de89ce39c87656d199e296 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Fri, 3 Jul 2026 20:47:18 +0200 Subject: [PATCH] fix(env): preserve empty service variable values (#10850) --- app/Models/EnvironmentVariable.php | 2 +- .../EnvironmentVariableValueCastingTest.php | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/EnvironmentVariableValueCastingTest.php diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index bfb02a470..e346e59d1 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -356,7 +356,7 @@ private function get_environment_variables(?string $environment_variable = null) private function set_environment_variables(?string $environment_variable = null): ?string { - if (is_null($environment_variable) && $environment_variable === '') { + if (is_null($environment_variable)) { return null; } $environment_variable = trim($environment_variable); diff --git a/tests/Feature/EnvironmentVariableValueCastingTest.php b/tests/Feature/EnvironmentVariableValueCastingTest.php new file mode 100644 index 000000000..6df78c134 --- /dev/null +++ b/tests/Feature/EnvironmentVariableValueCastingTest.php @@ -0,0 +1,45 @@ + 'NULL_VALUE', + 'value' => null, + 'resourceable_type' => Application::class, + 'resourceable_id' => 1, + ]); + + $rawValue = DB::table('environment_variables') + ->where('id', $env->id) + ->value('value'); + + expect($rawValue)->toBeNull(); + + $env->refresh(); + expect($env->value)->toBeNull(); +}); + +it('preserves intentional empty string environment variable values', function () { + $env = EnvironmentVariable::create([ + 'key' => 'EMPTY_STRING_VALUE', + 'value' => '', + 'resourceable_type' => Application::class, + 'resourceable_id' => 1, + ]); + + $rawValue = DB::table('environment_variables') + ->where('id', $env->id) + ->value('value'); + + expect($rawValue)->not->toBeNull() + ->and(decrypt($rawValue))->toBe(''); + + $env->refresh(); + expect($env->value)->toBe(''); +});