Skip to content

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

Open
SichenLiang wants to merge 1 commit into
uutils:mainfrom
SichenLiang:malformed-script-errors
Open

SichenLiang wants to merge 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

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.85%. Comparing base (95804a2) to head (05a5338).

Files with missing lines Patch % Lines
src/sed/compiler.rs 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #571      +/-   ##
==========================================
- Coverage   83.86%   83.85%   -0.02%     
==========================================
  Files          14       14              
  Lines        7203     7209       +6     
  Branches      424      426       +2     
==========================================
+ Hits         6041     6045       +4     
- Misses       1157     1159       +2     
  Partials        5        5              
Flag Coverage Δ
macos_latest 84.96% <66.66%> (-0.02%) ⬇️
ubuntu_latest 85.16% <66.66%> (-0.02%) ⬇️
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.

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 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 improve performance by 3.34%

⚠️ 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

⚡ 3 improved benchmarks
✅ 8 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ access_log_no_subst 1.1 s 1.1 s +3.45%
⚡ access_log_all_del 1.2 s 1.1 s +3.34%
⚡ access_log_no_del 1.1 s 1.1 s +3.23%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing SichenLiang:malformed-script-errors (05a5338) with main (95804a2)

Open in CodSpeed

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