Skip to content

sed: make the v command work on input and in scripts - #622

Open
jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:version-command
Open

jayhemnani9910 wants to merge 2 commits into
uutils:mainfrom
jayhemnani9910:version-command

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

v panics as soon as there is input:

$ printf 'x\n' | sed v
thread 'main' panicked at src/sed/processor.rs:945:22:
invalid command code
$ printf 'x\n' | /usr/bin/sed v    # GNU sed 4.9
x

The existing tests only run v with no input, so they don't reach the processor. Two more problems in the compiler:

  • the version runs to the end of the line, so v;p, v 4.2;p and {v} fail with "invalid version of sed";
  • each part is compared with 4.9.0 on its own (minor <= 9 && patch == 0), so v 4.2.2 and v 3.10 fail with "expected newer version of sed", though both are older than 4.9.

The processor now does nothing for v, like :. The version ends at a blank, ; or }, and it is compared with 4.9 part by part. I checked these against GNU sed 4.9 and they all match: v, v;p, v 4.2;p, v 4.2 p, {v}, {v;p}, v4.2, v 4.2.2, v 3.10, v 1.2.3.4 and v 4.9 succeed; v 4.9.0, v 4.9.1, v 4.10 and v 5 fail with "expected newer version of sed". Not changed: a non-numeric version like v abc, or a part above 255 like v999, still gives "invalid version of sed" (GNU says "expected newer version"). That is what test_invalid_only_major_version expects. An address before v is still rejected.

Tests: test_version_with_input, test_version_followed_by_command and test_version_compared_part_by_part fail without the change. cargo test: 357 passed (354 on main), clippy clean.

`v` compiled to a command the processor did not know, so any script
with `v` panicked ("invalid command code") on the first input line. The
version also ran to the end of the line, so `v;p`, `v 4.2;p` and `{v}`
failed with "invalid version of sed", and the parts were compared one
by one against 4.9.0, which rejected 4.2.2 and 3.10.

Do nothing for `v` at run time, end the version at a blank, ';' or '}',
and compare it with 4.9 part by part, as GNU sed does.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.46%. Comparing base (301a2b7) to head (39d9632).
⚠️ Report is 37 commits behind head on main.

Files with missing lines Patch % Lines
src/sed/compiler.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #622      +/-   ##
==========================================
+ Coverage   95.07%   95.46%   +0.38%     
==========================================
  Files          14       14              
  Lines        7436     7713     +277     
  Branches      439      458      +19     
==========================================
+ Hits         7070     7363     +293     
+ Misses        365      349      -16     
  Partials        1        1              
Flag Coverage Δ
macos_latest 96.92% <91.66%> (+0.34%) ⬆️
ubuntu_latest 96.85% <91.66%> (+0.33%) ⬆️
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.

Comment thread src/sed/compiler.rs Outdated
Err(_) => compilation_error(lines, line, "invalid version of sed"),
},
Err(_) => compilation_error(lines, line, "invalid version of sed"),
line.eat_spaces();

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.

the main loop already skips blanks and ;, do we need these lines?

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.

No, removed in 39d9632. v;p, v 4.2 p and {v;p} still pass.

Comment thread tests/by-util/test_sed.rs
new_ucmd!().args(&[version]).succeeds();
}
for version in ["v4.9.0", "v4.9.1", "v5"] {
new_ucmd!()

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 add v4.9 to the passing list and v4.10 to the failing one? both are in the description

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.

Added both in 39d9632.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 04:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

3 participants