Skip to content

sed: treat unknown regex escapes as literal characters - #664

Open
Himanshu-singh04 wants to merge 2 commits into
uutils:mainfrom
Himanshu-singh04:fix/658-unknown-regex-escapes
Open

Himanshu-singh04 wants to merge 2 commits into
uutils:mainfrom
Himanshu-singh04:fix/658-unknown-regex-escapes

Conversation

@Himanshu-singh04

Copy link
Copy Markdown

Fixes #658.

Unknown regex escapes were passed through to the Rust regex engine, which gave some of them a different meaning or rejected them. Emit unknown escaped ASCII letters and zero as literal characters while preserving sed's recognized regex escapes and backreferences.

Added an integration regression for \D, \A, \0, and \p. The test failed on main and passes with the change.

Validation:

  • cargo test --quiet (408 unit tests and 365 integration tests passed; 2 existing integration tests ignored)
  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • git diff --check

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (6ae5577) to head (44daae0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #664      +/-   ##
==========================================
+ Coverage   95.25%   96.68%   +1.43%     
==========================================
  Files          14       14              
  Lines        7500     7393     -107     
  Branches      442      437       -5     
==========================================
+ Hits         7144     7148       +4     
+ Misses        355      244     -111     
  Partials        1        1              
Flag Coverage Δ
macos_latest ?
ubuntu_latest 96.68% <100.00%> (+<0.01%) ⬆️
windows_latest ?

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/delimited_parser.rs Outdated
result.push(b'\\');
// Unknown letter and zero escapes are literal in sed, even
// when the regex engine gives them another meaning.
if !(line.current().is_ascii_alphanumeric()

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 double negation is hard to read
could be something like let c = line.current(); if c == '0' || (c.is_ascii_alphabetic() && !is_gnu_regex_escape(c, regex_mode)) then push only the char, no?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Simplified the condition by naming the current character and testing the literal escape case directly in 44daae0.

Comment thread tests/by-util/test_sed.rs
for (script, input, expected) in [
(r"s/\D/X/", "aDb1\n", "aXb1\n"),
(r"s/\A/X/", "xAy\n", "xXy\n"),
(r"s/\0/X/", "x0y\n", "xXy\n"),

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 also add a case with -E and one with an address, e.g. /\D/p

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added an -E substitution case and an address case using /\D/p in 44daae0.

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 - regex escapes unknown to GNU (\D, \A, \0, \p, ...) get Perl meaning or are rejected

2 participants