Skip to content

sed: don't write a missing final newline on Q, as GNU sed does - #597

Merged
sylvestre merged 3 commits into
uutils:mainfrom
DePasqualeOrg:fix-q-missing-newline
Oct 10, 2026
Merged

sylvestre merged 3 commits into
uutils:mainfrom
DePasqualeOrg:fix-q-missing-newline

Conversation

@DePasqualeOrg

@DePasqualeOrg DePasqualeOrg commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

When the last line of input has no final newline, GNU sed's Q quits without writing it, while q writes it. uutils sed writes it for both: printf a | sed 'p;Q' prints a and a newline, while GNU sed prints only a. This PR adds a quit_silently flag that Q sets, so that only q writes the newline.

@codspeed

codspeed Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing DePasqualeOrg:fix-q-missing-newline (3e861c8) with main (cccbcec)

Open in CodSpeed

@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.85%. Comparing base (cccbcec) to head (3e861c8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #597   +/-   ##
=======================================
  Coverage   94.85%   94.85%           
=======================================
  Files          14       14           
  Lines        7226     7230    +4     
  Branches      431      432    +1     
=======================================
+ Hits         6854     6858    +4     
  Misses        371      371           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.39% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.33% <100.00%> (+<0.01%) ⬆️
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.

@DePasqualeOrg
DePasqualeOrg marked this pull request as ready for review October 6, 2026 08:13
Comment thread src/sed/processor.rs

if context.stop_processing {
output.flush_pending_newline()?;
if !context.quit_silently {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a new flag? Q already sets quiet.
what does GNU give for printf a | sed -n 'p;q'? if it's a without newline, !context.quiet would be enough here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GNU sed’s -n 'p;q' outputs "a\n", so quiet cannot distinguish q from Q. The separate flag is needed.

Comment thread tests/by-util/test_sed.rs
.pipe_in("a")
.succeeds()
.stdout_is("a");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please also check p;q gives a\na here, so we cover the difference between q and Q?

@sylvestre
sylvestre merged commit 96afb29 into uutils:main Oct 10, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

2 participants