Fix last env variable not read when .env file has no trailing newline#4783
Fix last env variable not read when .env file has no trailing newline#4783SasinduDilshara wants to merge 1 commit intowso2:masterfrom
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 36 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughUpdated the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When using --env-file, the POSIX `read` builtin returns non-zero on EOF even when partial content is read, causing the last variable to be silently dropped if the file has no trailing newline. Fix by adding `|| [ -n "$key" ]` to handle the incomplete final line. Adds integration test testConfigurablePropertyWithEnvFileNoTrailingNewline to cover this scenario. Fixes wso2#4234 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ee7dccd to
eb0ec59
Compare
Claude Issue Analysis — [Issue #4234]: When there is no new line in the .env file, the last environmental variable value is not picked.Classification
Reproducibility
Root Cause AnalysisThe bug is in while IFS='=' read -r key value; do
...
done < "$file_path"The POSIX The fix is to also process a partial line after the # Option 1: handle last incomplete line after the loop
while IFS='=' read -r key value || [ -n "$key" ]; doAdding The VSCode extension is unaffected because it likely sets env vars through a different mechanism (process environment injection) that doesn't use the shell script's file-parsing loop. Test Coverage Assessment
|
|
#Claude Fix Verification Report Issue: #4234 Reproduction Steps Executed
ResultThe API returned HTTP 200 with both variables correctly resolved: {
"name": "env",
"msg": "Hello"
}
Before the fix, this scenario produced: EvidenceShell script fix (line 133 of patched while IFS='=" read -r key value || [ -n "$key" ]; doServer log — no ConfigDeployer errors: Server log — CAR deployed successfully: Server log — server started cleanly: HTTP response (curl): Both |
Summary
Fixes #4234
export_env_file()function in all startup scripts usedwhile IFS='=' read -r key value; do, which skips the last line when the.envfile has no trailing newline (bashreadreturns non-zero at EOF).while IFS='=' read -r key value || [ -n "$key" ]; doso the loop body executes even whenreadhits EOF without a newline, as long as data was read into$key.distribution/src/scripts/micro-integrator.sh) and all 14 integration-test copies.Root Cause
The
readbuiltin returns non-zero when it reaches EOF before finding\n. Thewhilecondition check on the return code causes the last key-value pair to be silently skipped.Test plan
.envfile without a trailing newline (e.g.printf 'KEY=value') and start MI with--env-file; confirm the variable is exported and resolved.🤖 Generated with Claude Code
Summary by CodeRabbit