Skip to content

sed: with --posix, reject Q, q exit codes, addr,+N and the I/M modifiers - #703

Merged
sylvestre merged 2 commits into
uutils:mainfrom
Xnadir:posix-reject-gnu-extensions
Nov 26, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
Xnadir:posix-reject-gnu-extensions

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

With --posix, GNU sed refuses these GNU extensions when it compiles the script, and exits 1. uutils sed accepted and ran them:

  • addr1,+N ranges (1,+1p): unexpected ,'`
  • the Q command: unknown command
  • an exit code after q (q5, $q 5): extra characters after command
  • the I and M address modifiers (/A/Ip, /a/Mp): unknown command

Each is now a compile error under --posix. Without --posix nothing changes. The messages follow GNU's wording in uutils' own error format. l N from the same issue is left out, because #345 and #552 already reject it.

The new test covers each case with --posix, and checks that 1,+1p, /A/Ip and Q still work without it. It fails on main. The rest of the suite is unchanged (the 48 tests that fail on Windows main because of CRLF still fail here, no new ones).

Closes #650

AI disclosure: written with help from Claude Code.

🤖 Generated with Claude Code

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

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.

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (1a27699) to head (f91ba91).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #703   +/-   ##
=======================================
  Coverage   94.14%   94.15%           
=======================================
  Files          14       14           
  Lines        5741     5745    +4     
  Branches      458      463    +5     
=======================================
+ Hits         5405     5409    +4     
  Misses        335      335           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.12% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.00% <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.

@codspeed

codspeed Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 11 untouched benchmarks


Comparing Xnadir:posix-reject-gnu-extensions (f91ba91) with main (1a27699)

Open in CodSpeed

Comment thread src/sed/compiler.rs Outdated
}

// addr1,+N is a GNU extension.
if context.posix && !line.eol() && line.current() == '+' {

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 be dedup with the check just below, no?
something like (is_address_char(c) || (c == '+' && !context.posix)) in has_addr2

Comment thread src/sed/compiler.rs Outdated
}
match line.current() {
// The I and M modifiers are GNU extensions.
c @ ('I' | 'M') if context.posix => {

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.

why not just 'I' if !context.posix and 'M' if !context.posix so it breaks and the command parser rejects it?
it would be consistent with Q/z/W ("invalid command code")

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the PR!
cargo test fails on linux, macOS and windows, please have a look.
The inline comments are two simplifications.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:01

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.

Xnadir and others added 2 commits November 26, 2026 06:24
These are GNU extensions, and GNU sed --posix refuses them when the
script is compiled. Leave `l N` to uutils#345 and uutils#552, which already reject it.

Closes uutils#650

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-up. The +N check is part of has_addr2, and I/M are left to
the command parser under --posix ("invalid command code"), like Q. The
test no longer pipes input to scripts sed rejects before reading it,
which failed with a broken pipe on Linux and macOS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xnadir
Xnadir force-pushed the posix-reject-gnu-extensions branch from a4bdf20 to f91ba91 Compare November 26, 2026 01:26
Copilot AI balanced review requested due to automatic review settings November 26, 2026 01:26

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.

@sylvestre
sylvestre merged commit c225cb8 into uutils:main Nov 26, 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.

sed - --posix still accepts Q, q/l arguments, +N ranges and the I address modifier

3 participants