Skip to content

sed: write the newline a file's last line lacks before the next file's output, as GNU sed does - #596

Open
DePasqualeOrg wants to merge 2 commits into
uutils:mainfrom
DePasqualeOrg:fix-separator-between-files
Open

DePasqualeOrg wants to merge 2 commits into
uutils:mainfrom
DePasqualeOrg:fix-separator-between-files

Conversation

@DePasqualeOrg

@DePasqualeOrg DePasqualeOrg commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

When an input file's last line has no final newline and another file follows, GNU sed writes the missing newline before the next output. uutils sed drops it, so the last line of one file runs into the first output of the next: with printf a > 1 and printf 'b\n' > 2, sed '' 1 2 prints ab instead of a and b on separate lines. The same happens in w and W files.

This PR carries the deferred newline from one file's output buffer to the next, and gives NamedWriter the same deferred newline for w, W and s///w files. W now passes its first line without the newline, so that the writer knows whether the line ended. With -i, each file keeps its own output, so nothing is carried between files.

0r now writes its file before a newline carried over from the previous file, which then comes before that file's first line, as in GNU sed. copy_file gains a variant that leaves the deferred newline in place for this.

-z is still ignored, so with -z the files also get a newline between them, as they do without it.

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.98%. Comparing base (96afb29) to head (2a6a4c7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #596      +/-   ##
==========================================
+ Coverage   94.85%   94.98%   +0.13%     
==========================================
  Files          14       14              
  Lines        7230     7265      +35     
  Branches      432      432              
==========================================
+ Hits         6858     6901      +43     
+ Misses        371      363       -8     
  Partials        1        1              
Flag Coverage Δ
macos_latest 96.52% <100.00%> (+0.13%) ⬆️
ubuntu_latest 96.46% <100.00%> (+0.12%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 9 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ access_log_append 1 s 1 s -2.01%
⚡ access_log_translit 1,019.5 ms 989.7 ms +3.02%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing DePasqualeOrg:fix-separator-between-files (2a6a4c7) with main (96afb29)

Open in CodSpeed

@DePasqualeOrg
DePasqualeOrg force-pushed the fix-separator-between-files branch from f00be9e to d572850 Compare October 10, 2026 18:18
@DePasqualeOrg
DePasqualeOrg marked this pull request as ready for review October 10, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant