Skip to content

xargs: keep empty items with -0 and -d - #894

Open
SichenLiang wants to merge 1 commit into
uutils:mainfrom
SichenLiang:xargs-keep-empty-items
Open

SichenLiang wants to merge 1 commit into
uutils:mainfrom
SichenLiang:xargs-keep-empty-items

Conversation

@SichenLiang

Copy link
Copy Markdown
Contributor

xargs -0 and xargs -d dropped empty items at the beginning, middle, or end of the input. GNU passes each empty item to the command.

Keep empty records in the byte-delimited reader. The default whitespace parser is unchanged, so blank input lines still do not become empty arguments.

This also makes the existing item-based options see the empty records: -n, -L, -s, and -I now count or substitute them, and -r still suppresses a command only when there are no input items at all.

Tests cover NUL and explicit delimiters, empty items in each position, their interaction with -r, -n, and -I, and the reader itself.

Fixes #889

@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.29%. Comparing base (8f17c13) to head (6243028).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #894      +/-   ##
==========================================
+ Coverage   92.27%   92.29%   +0.01%     
==========================================
  Files          35       35              
  Lines        7576     7590      +14     
  Branches      393      394       +1     
==========================================
+ Hits         6991     7005      +14     
  Misses        443      443              
  Partials      142      142              

☔ 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 4, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing SichenLiang:xargs-keep-empty-items (c19fd7d) with main (8f17c13)

Open in CodSpeed

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Commit 6243028 has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 317 / PASSED: 274 / FAILED: 37 / SKIPPED: 6
  Reference: TOTAL: 316 / PASSED: 273 / FAILED: 37 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +1
  FAILED: +0

Comment thread src/xargs/mod.rs Outdated
let mut args: Box<dyn ArgumentReader> = if let Some(delimiter) = options.delimiter {
Box::new(ByteDelimitedArgumentReader::new(args_file, delimiter))
let mut reader = ByteDelimitedArgumentReader::new(args_file, delimiter);
reader.keep_empty = options.null || matches.contains_id(options::DELIMITER);

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 keep_empty be a parameter of new() instead of setting the field afterwards?
it would also be nicer to compute it once when the delimiter is resolved, rather than checking matches again 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.

Done. keep_empty is now passed to ByteDelimitedArgumentReader::new() and computed once in normalize_options, after the delimiter is resolved. do_xargs no longer checks matches here.
The flag is still needed because -I by itself also uses this reader with a newline delimiter, and GNU skips empty lines in that case.

The byte-delimited reader discarded empty records. Keep them so -0 and
-d pass empty input items to the command, as GNU xargs does.

Leave the default whitespace parser unchanged and add coverage for empty
records with -r, -n and -I.
@SichenLiang
SichenLiang force-pushed the xargs-keep-empty-items branch from 6243028 to c19fd7d Compare October 5, 2026 04:41
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Commit c19fd7d has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 317 / PASSED: 274 / FAILED: 37 / SKIPPED: 6
  Reference: TOTAL: 316 / PASSED: 273 / FAILED: 37 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +1
  FAILED: +0

@sylvestre

Copy link
Copy Markdown
Contributor

sorry but it needs to be rebased

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.

xargs: empty items are dropped with -0 and -d

2 participants