Skip to content

sed: treat \< and \> as regex syntax when choosing the matcher - #612

Merged
sylvestre merged 1 commit into
uutils:mainfrom
jayhemnani9910:word-boundaries-literal-path
Oct 24, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
jayhemnani9910:word-boundaries-literal-path

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

\< and \> only work when something else in the pattern makes it a regular expression. On their own they go to the literal matcher, which drops the backslash, so sed looks for a real < or >:

$ echo 'foo <foo> food' | ./target/debug/sed 's/\<foo\>/X/g'
foo X food
$ echo 'foo <foo> food' | /usr/bin/sed 's/\<foo\>/X/g'    # GNU sed 4.9
X <X> food

s/\<f.o\>/X/g already gives X <X> food, since the . sends it to the regex engine. Addresses are affected the same way: /\<bar/p prints <bar but not bar.

NEEDS_RE already lists \b and \B as empty matches that need a regular expression. This adds \< and \> next to them. Both engines read them as word start and word end. --posix is unchanged, since there the parser already turns them into plain < and >.

Tests: test_needs_re_matches gets \<foo and foo\>, and test_word_boundaries_without_other_regex_characters checks s/\<foo\>/X/g and /\<bar/p against GNU sed 4.9's output. Both fail without the change. cargo test: 747 passed (746 on main plus the new one), clippy and rustfmt clean.

A pattern with no other regular expression characters, such as
s/\<foo\>/X/g, went to the literal matcher, which drops the backslashes.
It then replaced the text "<foo>" and left the word foo alone. Add \< and
\> to the escapes that need a regular expression, next to \b and \B.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 05:56

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 reached their quota limit.

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 Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.94%. Comparing base (3e86e42) to head (2cf1706).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #612   +/-   ##
=======================================
  Coverage   94.93%   94.94%           
=======================================
  Files          14       14           
  Lines        7292     7294    +2     
  Branches      434      434           
=======================================
+ Hits         6923     6925    +2     
  Misses        368      368           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.46% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.40% <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 Oct 20, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 14.37%

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

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

⚡ 1 improved benchmark
✅ 10 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ number_fix 1.3 s 1.1 s +14.37%

Tip

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


Comparing jayhemnani9910:word-boundaries-literal-path (2cf1706) with main (3e86e42)

Open in CodSpeed

@sylvestre
sylvestre merged commit d804abd into uutils:main Oct 24, 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.

3 participants