Repository navigation
fix(sed): avoid replacing the final split sentinel - #1291
Open
sergioperezcheco wants to merge 2 commits into
Open
sergioperezcheco wants to merge 2 commits into
sergioperezcheco wants to merge 2 commits into
Conversation
Assisted-by: AI tooling for implementation, testing and automated review Signed-off-by: sergioperezcheco <checo520@outlook.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1291 +/- ##
==========================================
+ Coverage 97.17% 97.20% +0.02%
==========================================
Files 36 36
Lines 1523 1536 +13
==========================================
+ Hits 1480 1493 +13
Misses 43 43 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nfischer
requested changes
Oct 25, 2026
|
|
||
| test('line anchors do not replace the split sentinel after a final newline', t => { | ||
| const file = `${t.context.tmp}/anchors.txt`; | ||
| const cases = [ |
Contributor
Author
There was a problem hiding this comment.
Unrolled in 691bcf0 — each case is now its own write/assert block, same five inputs. npx ava test/sed.js passes (28 tests) and eslint is clean.
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.
Problem
sed()passes the final empty element fromsplit('\n')toString.replace()even when it is only the sentinel after a terminating newline. Anchored or empty-matching replacements can append text after the final newline, and callbacks receive a nonexistent input line. For example, applying/^/with'> 'toone\ncurrently produces> one\n>instead of> one\n.Change
Remove only the split sentinel before replacing real lines, then restore the original terminating newline. Preserve real blank lines, CRLF characters, unterminated input, and existing empty-file behavior. Preserve standard sticky RegExp state across newline-terminated files and calls without executing an extra replacement or callback; unterminated-input state is unchanged.
Regression tests cover file and piped inputs, in-place replacement, callbacks, blank lines and sticky state. This is separate from the multi-file separator fix in #1261 and does not claim to fix #952 or reopen an older issue.
Validation
macOS / Node 22.22.3:
npm test, including posttest ESLint: 662 passed, 6 existing skips.npm run test-with-coverage: 662 passed, 6 skipped;src/sed.jshas 100% statement/branch/function/line coverage.git diff --checkpassed.npm packand extracted-package public API: 22 assertions pass. The same public probe with unchanged upstream sed source fails at the first anchored EOF case.Other operating systems and Node versions have not been run locally. Hosted CI and human review are not claimed.
AI-assisted implementation, testing and automated review; no human review is claimed.