Skip to content

fix(sed): treat ( ) { } + ? | as literal in basic regular expressions - #239

Merged
ferdingler merged 2 commits into
strands-agents:mainfrom
Revinand:fix/sed-bre-literal-metachars
Nov 11, 2026
Merged

ferdingler merged 2 commits into
strands-agents:mainfrom
Revinand:fix/sed-bre-literal-metachars

Conversation

@Revinand

Copy link
Copy Markdown
Contributor

Description

sed patterns are POSIX basic regular expressions, but bre_to_ere only converted \( \) \{ \} and let a bare ( ) { } + ? | through to the regex crate as operators. As a result s/call(x)/run(x)/ silently did nothing, s/a|b/X/ replaced only the a, and address patterns such as /f(x)/p, which skipped the conversion, matched nothing.

This change:

  • escapes the bare characters, and maps the GNU \+ \? \| to operators;
  • keeps a leading * and a $ that is not at the end literal, as POSIX does;
  • converts address patterns too, once at parse time instead of on every line;
  • supports -E, -r and --regexp-extended, which were accepted but ignored, and adds -E, -r to sed --help.

Scripts that relied on ERE syntax without -E, such as sed 's/a+/X/', now treat those characters literally, as GNU sed does. With -E they work as before. A ^ in the middle of a pattern is still an anchor, while GNU sed treats it literally; I left that unchanged to keep this PR focused.

Related Issues

Fixes #181

Type of Change

Bug fix

Testing

Added 10 sed_bre_* and sed_ere_* cases to tests/shell_integration.rs; GNU sed 4.9 gives the same output for each. Six of them fail without the change, and the other four (interval, final $, $ before \), and -E with groups and alternation) check behavior that has to keep working. cargo xtask check --rust-only passes.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Revinand
Revinand requested a review from a team as a code owner November 10, 2026 15:23
@ferdingler
ferdingler merged commit 739fa1f into strands-agents:main Nov 11, 2026
30 checks passed
@ferdingler

Copy link
Copy Markdown
Collaborator

thanks for the contribution @Revinand

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.

[BUG] sed treats ( ) { } + ? | as regex operators in basic regular expressions

2 participants