Skip to content

compiler: report an unterminated s or y command instead of aborting - #571

Merged
sylvestre merged 1 commit into
uutils:mainfrom
SichenLiang:malformed-script-errors
Oct 6, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
SichenLiang:malformed-script-errors

Conversation

@SichenLiang

@SichenLiang SichenLiang commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #570.

After #578 fixed the address-parser cases from #570, the remaining aborts are scripts that end immediately after s or y. Both command compilers tried to read a delimiter without first checking for the end of the line.

They now return a compilation error with GNU sed's wording instead:

$ sed s </dev/null
sed: <script argument 1>:1:2: error: unterminated `s' command

The new table test covers s, 1s, p;s, y, and {y, and checks the complete diagnostic for each case.

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.84%. Comparing base (d43d4de) to head (8ee2974).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #571   +/-   ##
=======================================
  Coverage   94.84%   94.84%           
=======================================
  Files          14       14           
  Lines        7211     7217    +6     
  Branches      427      429    +2     
=======================================
+ Hits         6839     6845    +6     
  Misses        371      371           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.38% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.32% <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.

Comment thread src/sed/compiler.rs
Ok(Address::Line(number))
}
_ => panic!("invalid context address"),
_ => compilation_error(lines, line, "expected context address"),

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.

GNU says "unexpected ,'" for 2,d`, could we match it?
please check with LANG=C sed -e '2,d'

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.

You're right. #578 now makes 2,d report unexpected `,', so I removed the address-parser changes from this PR. It now only handles scripts ending after s or y.

Comment thread tests/by-util/test_sed.rs Outdated
// A script that ends in the middle of an address or of an s/y delimiter must
// produce a diagnostic, not abort.
#[test]
fn incomplete_script_reports_an_error() {

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.

please prefix with test_ like the rest of the file

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.

Renamed to test_unterminated_s_or_y_command.

Comment thread tests/by-util/test_sed.rs Outdated
.args(&["-e", script])
.fails()
.code_is(1)
.stderr_contains(*message);

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.

please use stderr_is with the full message like the other tests in this file

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.

Updated. Each case now checks the complete diagnostic with stderr_is.

@SichenLiang
SichenLiang force-pushed the malformed-script-errors branch from a4d2c85 to 05a5338 Compare October 2, 2026 01:53
@SichenLiang SichenLiang changed the title compiler: report malformed scripts instead of aborting compiler: report an unterminated s or y command instead of aborting Oct 2, 2026
@SichenLiang

Copy link
Copy Markdown
Contributor Author

Rebased on current main and updated the title and description to the narrower scope.

@codspeed

codspeed Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing SichenLiang:malformed-script-errors (8ee2974) with main (d43d4de)

Open in CodSpeed

The substitution and transliteration compilers read the delimiter with
ScriptCharProvider::current() even when the command letter was the last
character on the line. This indexed past the end of the line and
aborted.

Check for the end of the line first and report an unterminated command,
as GNU sed does. Scripts such as `s`, `1y`, and `p;s` now exit 1 with a
diagnostic instead of aborting.

The address-parser aborts from uutils#570 were fixed separately in uutils#578.
@SichenLiang
SichenLiang force-pushed the malformed-script-errors branch from 05a5338 to 8ee2974 Compare October 5, 2026 17:26
@sylvestre
sylvestre merged commit e6829c3 into uutils:main Oct 6, 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.

Malformed scripts abort instead of reporting a compilation error

2 participants