Skip to content

fix: correct newline handling for p and x commands#378

Open
pocopepe wants to merge 3 commits intouutils:mainfrom
pocopepe:issue-306-143
Open

fix: correct newline handling for p and x commands#378
pocopepe wants to merge 3 commits intouutils:mainfrom
pocopepe:issue-306-143

Conversation

@pocopepe
Copy link
Copy Markdown
Contributor

Fixes #306 and #143

  • Hold space was initialized without has_newline: true, causing 1x to output nothing instead of an empty line when input has no trailing newline
  • p was unconditionally appending \n, breaking -n p on no-newline input

Fixed by initializing hold space as newline terminated and adding a pending_newline mechanism in OutputBuffer that defers newline injection until the next write, so -n mode never triggers it
Also incidentally fixes the g/G empty hold space behavior from #266 (overlaps with open PR #263 same bug, different approach)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 78.57143% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.25%. Comparing base (7b204c0) to head (22b5356).

Files with missing lines Patch % Lines
src/sed/fast_io.rs 79.34% 18 Missing and 1 partial ⚠️
src/sed/processor.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #378      +/-   ##
==========================================
- Coverage   82.25%   82.25%   -0.01%     
==========================================
  Files          13       13              
  Lines        5438     5522      +84     
  Branches      304      310       +6     
==========================================
+ Hits         4473     4542      +69     
- Misses        963      977      +14     
- Partials        2        3       +1     
Flag Coverage Δ
macos_latest 82.94% <93.90%> (+0.23%) ⬆️
ubuntu_latest 83.04% <93.90%> (+0.23%) ⬆️
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 Sentry.
📢 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-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will degrade performance by 6.47%

⚠️ 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
❌ 3 regressed benchmarks
✅ 7 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
access_log_no_op 747.7 ms 781.1 ms -4.27%
access_log_append 634.7 ms 669.7 ms -5.23%
access_log_all_del 541.5 ms 523.7 ms +3.39%
no_op_short 964 ms 1,030.6 ms -6.47%

Comparing pocopepe:issue-306-143 (22b5356) with main (7b204c0)

Open in CodSpeed

Copy link
Copy Markdown
Collaborator

@dspinellis dspinellis left a comment

Choose a reason for hiding this comment

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

LGTM. Please squash the commits into a single one.

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.

1x should output empty line if input doesn't contain newline

2 participants