Repository navigation
Fix/installer trim whitespace db inputs - #404
Merged
navneetkumar-pim-webkul merged 3 commits intoMay 26, 2026
Merged
navneetkumar-pim-webkul merged 3 commits into
navneetkumar-pim-webkul merged 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the unopim:install interactive installer by trimming whitespace from user-entered .env values (especially DB settings) and adding prompt-level validation to prevent writing unusable connection details that can break migrations.
Changes:
- Add trim transforms + whitespace/port validation for database prompts (host/port/name/username) and apply post-prompt trimming as an extra safeguard.
- Extend trimming to other installer prompts (APP_* fields, Elasticsearch text inputs, admin name/email) while leaving passwords untrimmed.
- Add new Pest feature tests covering trimming behavior for DB inputs and host whitespace rejection.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/Webkul/Installer/src/Console/Commands/Installer.php | Adds trimming and validation to installer prompt inputs (DB/app/Elasticsearch/admin) before writing to .env. |
| packages/Webkul/Installer/tests/Feature/DatabaseInputTrimTest.php | Adds feature tests to verify DB prompt trimming and whitespace rejection behavior. |
Comments suppressed due to low confidence (2)
packages/Webkul/Installer/src/Console/Commands/Installer.php:352
- The empty-credentials guard uses negation on string values (e.g.
! $databaseDetails['DB_PASSWORD']), which treats the string'0'as falsey in PHP. That means a valid value like'0'for DB_DATABASE/DB_USERNAME/DB_PASSWORD would be incorrectly rejected. Prefer explicit empty-string checks (e.g.trim(...) === '') for these required inputs.
if (
! $databaseDetails['DB_DATABASE']
|| ! $databaseDetails['DB_USERNAME']
|| ! $databaseDetails['DB_PASSWORD']
) {
return $this->error('Please enter the database credentials.');
}
packages/Webkul/Installer/src/Console/Commands/Installer.php:611
$input ?: $defaultValuetreats the string'0'as empty/falsey and will unexpectedly replace it with the default. If you want to only fall back when the user truly provided an empty string, use a strict empty check ($input === '') or the null-coalescing pattern depending on whattext()returns.
$input = text(
label: $question,
default: $defaultValue,
required: true,
transform: trim(...),
);
$this->envUpdate($key, $input ?: $defaultValue);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
php artisan unopim:installaccepted whitespace in DB inputs and wroteDB_HOST="127.0.0.1 "to.env, causinggetaddrinfo for "127.0.0.1" failedduring migrations.DB_PREFIXhadtransform: trim(...); every other text input passed the raw value straight through toenvUpdate(), which quote-wraps anything containing whitespace.DB_HOST,DB_PORT,DB_DATABASE,DB_USERNAMEat the prompt level and again after the prompt array is built (defense-in-depth, mirrors the existingDB_PREFIXpattern). Same trim treatment extended toAPP_NAME,APP_URL, every Elasticsearch text input, and the admin name/email inputs. Passwords intentionally left untrimmed..env.Test plan
vendor/bin/pest packages/Webkul/Installer/tests/Feature/DatabaseInputTrimTest.php— 5 new tests, all passing (DB_HOST trailing whitespace, DB_HOST internal whitespace rejection, DB_PORT/DB_DATABASE/DB_USERNAME trim)vendor/bin/pest --testsuite="Installer Feature Test"— 32 passed (134 assertions), no regressions in existingDatabasePrefixTrimTest,CommandTest,InstallerControllerTest, etc.127.0.0.1␠␠␠at the host prompt now lands asDB_HOST=127.0.0.1(unquoted) in.env; entering127.0.0 .1is rejected with "The database host cannot contain whitespace."