xargs: -d '\0' is rejected, and octal escapes need a leading 0

Open Beginner friendly
#925 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cli

Research direction

Start with parse_delimiter in src/xargs/mod.rs and the test_delimiter_parsing test mentioned in the issue. Compare its escape parsing with the GNU examples in the body, then run the delimiter parsing tests. Done when the listed accepted and rejected escapes behave as described and the existing test reflects the intended \0 behavior.

Written by the indexing model from the issue text.

Description

$ printf 'a\0b' | xargs -d '\0' echo
Error: error: invalid value '\0' for '--delimiter <delimiter>': Invalid octal sequence: cannot parse integer from empty string
$ printf 'a\0b' | /usr/bin/xargs -d '\0' echo    # GNU findutils 4.10.0
a b
$ printf 'a:b' | xargs -d '\72' echo
Error: error: invalid value '\72' for '--delimiter <delimiter>': Invalid escape sequence: \72

GNU's manual says -d takes "an octal or hexadecimal escape code ... understood as for the printf command", and GNU xargs accepts \0, \72, \072, \101 and \0101. It rejects \400, \8 and \09.

In parse_delimiter (src/xargs/mod.rs:914), any escape that starts with 0 goes to the octal branch with the 0 removed, so \0 parses an empty string; the "0" => Ok(b'\0') arm below it never runs. Octal without a leading 0 isn't handled at all.

test_delimiter_parsing asserts parse_delimiter("\\0").is_err(), so matching GNU means changing that line. I have a fix that parses \ followed by octal digits as one octal value, with tests for the cases above; happy to open a PR if you want GNU's behaviour here.

uutils findutils main 505421d.

Dominant language
Rust
Stars
653
Forks
115
Avg merge
1d 4h
Merged PRs (30d)
27

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/findutils

All issues in uutils/findutils

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.