Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: limit comment field to 256 characters for environment variables

Andras Bacsai201c9fada342
diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php
index 33a2c83b97..75149a0d40 100644
--- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php
+++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php
@@ -65,7 +65,7 @@ class Show extends Component
protected $rules = [
'key' => 'required|string',
'value' => 'nullable',
- 'comment' => 'nullable|string|max:1000',
+ 'comment' => 'nullable|string|max:256',
'is_multiline' => 'required|boolean',
'is_literal' => 'required|boolean',
'is_shown_once' => 'required|boolean',
@@ -107,7 +107,7 @@ class Show extends Component
$this->validate([
'key' => 'required|string',
'value' => 'nullable',
- 'comment' => 'nullable|string|max:1000',
+ 'comment' => 'nullable|string|max:256',
'is_multiline' => 'required|boolean',
'is_literal' => 'required|boolean',
'is_shown_once' => 'required|boolean',
diff --git a/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php b/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php
index 0e17e720f4..abbae35736 100644
--- a/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php
+++ b/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php
@@ -12,11 +12,11 @@ return new class extends Migration
public function up(): void
{
Schema::table('environment_variables', function (Blueprint $table) {
- $table->text('comment')->nullable();
+ $table->string('comment', 256)->nullable();
});
Schema::table('shared_environment_variables', function (Blueprint $table) {
- $table->text('comment')->nullable();
+ $table->string('comment', 256)->nullable();
});
}
diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.php
index 259f908284..80b607bd77 100644
--- a/resources/views/livewire/project/shared/environment-variable/show.blade.php
+++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php
@@ -121,6 +121,7 @@
<x-forms.input disabled type="password" id="real_value" />
@endif
</div>
+ <x-forms.input disabled id="comment" label="Comment (Optional)" helper="Add a note to document what this environment variable is used for." maxlength="256" />
</div>
@else
<div class="flex flex-col w-full gap-2">
@@ -136,7 +137,7 @@
<x-forms.input :disabled="$is_redis_credential" :required="$is_redis_credential" disabled type="password" id="real_value" />
@endif
</div>
- <x-forms.input instantSave id="comment" label="Comment (Optional)" helper="Add a note to document what this environment variable is used for." />
+ <x-forms.input instantSave id="comment" label="Comment (Optional)" helper="Add a note to document what this environment variable is used for." maxlength="256" />
</div>
@endif
@else
@@ -148,9 +149,7 @@
<x-forms.input disabled type="password" id="real_value" />
@endif
</div>
- @if (!$isDisabled)
- <x-forms.input disabled id="comment" label="Comment (Optional)" helper="Add a note to document what this environment variable is used for." />
- @endif
+ <x-forms.input disabled id="comment" label="Comment (Optional)" helper="Add a note to document what this environment variable is used for." maxlength="256" />
</div>
@endcan
@can('update', $this->env)
diff --git a/tests/Feature/EnvironmentVariableCommentTest.php b/tests/Feature/EnvironmentVariableCommentTest.php
index 05126c23a7..5efb2b953c 100644
--- a/tests/Feature/EnvironmentVariableCommentTest.php
+++ b/tests/Feature/EnvironmentVariableCommentTest.php
@@ -85,7 +85,7 @@ test('environment variable comment is copied to preview environment', function (
'resourceable_id' => $this->application->id,
]);
- // The model's booted() method should create a preview version
+ // The model's created() event listener automatically creates a preview version
$previewEnv = EnvironmentVariable::where('key', 'TEST_VAR')
->where('resourceable_id', $this->application->id)
->where('is_preview', true)
@@ -118,3 +118,33 @@ test('developer view format does not break with comment-like values', function (
expect($env1->value)->toBe('value_with_#_in_it');
expect($env1->comment)->toBe('Contains hash symbol');
});
+
+test('environment variable comment can store up to 256 characters', function () {
+ $comment = str_repeat('a', 256);
+ $env = EnvironmentVariable::create([
+ 'key' => 'TEST_VAR',
+ 'value' => 'test_value',
+ 'comment' => $comment,
+ 'resourceable_type' => Application::class,
+ 'resourceable_id' => $this->application->id,
+ ]);
+
+ expect($env->comment)->toBe($comment);
+ expect(strlen($env->comment))->toBe(256);
+});
+
+test('environment variable comment cannot exceed 256 characters via Livewire', function () {
+ $env = EnvironmentVariable::create([
+ 'key' => 'TEST_VAR',
+ 'value' => 'test_value',
+ 'resourceable_type' => Application::class,
+ 'resourceable_id' => $this->application->id,
+ ]);
+
+ $longComment = str_repeat('a', 257);
+
+ Livewire::test(\App\Livewire\Project\Shared\EnvironmentVariable\Show::class, ['env' => $env, 'type' => 'application'])
+ ->set('comment', $longComment)
+ ->call('submit')
+ ->assertHasErrors(['comment' => 'max']);
+});