fix: preserve final line of config files lacking a trailing newline#1420
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1420 +/- ##
==========================================
- Coverage 88.48% 88.31% -0.16%
==========================================
Files 56 56
Lines 3767 3781 +14
==========================================
+ Hits 3333 3339 +6
- Misses 299 303 +4
- Partials 135 139 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes a data-loss bug in FileEdit.GenerateNewFile where the final line of a config file could be dropped when the file lacks a trailing newline, ensuring unmanaged content outside the managed # BEGIN_AWS_SSO_CLI / # END_AWS_SSO_CLI block is preserved.
Changes:
- Update
GenerateNewFileto write the final partial line returned alongsideio.EOF(both before locating the managed block and when copying the unmanaged tail). - Add unit tests covering config files that do not end with a trailing newline (both with and without an existing managed block).
- Document the fix in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/fileutils/fileedit.go | Writes EOF partial lines so the final unmanaged line isn’t dropped when there’s no trailing newline. |
| internal/fileutils/fileedit_test.go | Adds regression tests for no-trailing-newline inputs. |
| CHANGELOG.md | Notes the bugfix under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
GenerateNewFile dropped the last line of a file when it had no trailing newline, because bufio.Reader.ReadString returns a partial line with io.EOF together, and both copy loops exited before writing it. Fixes #1419
GenerateNewFile dropped the last line of a file when it had no trailing newline, because bufio.Reader.ReadString returns a partial line with io.EOF together, and both copy loops exited before writing it.
Fixes #1419