Repository navigation
sed: treat \< and \> as regex syntax when choosing the matcher - #612
Conversation
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.
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 14.37%
|
| 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)
|
Thanks for your PR |
\<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>:s/\<f.o\>/X/galready givesX <X> food, since the.sends it to the regex engine. Addresses are affected the same way:/\<bar/pprints<barbut notbar.NEEDS_REalready lists\band\Bas empty matches that need a regular expression. This adds\<and\>next to them. Both engines read them as word start and word end.--posixis unchanged, since there the parser already turns them into plain<and>.Tests:
test_needs_re_matchesgets\<fooandfoo\>, andtest_word_boundaries_without_other_regex_characterscheckss/\<foo\>/X/gand/\<bar/pagainst 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.