Repository navigation
sed: keep an escaped ^ or $ literal in a plain-string pattern - #638
qodelicious wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #638 +/- ##
==========================================
+ Coverage 95.07% 95.09% +0.01%
==========================================
Files 14 14
Lines 7436 7483 +47
Branches 439 440 +1
==========================================
+ Hits 7070 7116 +46
- Misses 365 366 +1
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:
|
| } | ||
|
|
||
| #[test] | ||
| fn test_escaped_anchors_in_literal_pattern() { |
There was a problem hiding this comment.
could you please run the GNU testsuite to check that nothing regresses?
setup: git clone https://github.com/mirror/sed.git ../gnu.sed
run: ./util/run-gnu-testsuite.sh
There was a problem hiding this comment.
Ran it with ./util/run-gnu-testsuite.sh on main and on this branch and got identical results for every test, so nothing regresses. The GNU testsuite job on the PR also says no new failures vs main.
| /// Construct a new matcher based on a literal pattern with possible | ||
| /// anchors and backslash escapes. An escaped `\^` or `\$` stands for | ||
| /// itself rather than an anchor. | ||
| pub fn new(pattern: impl AsRef<[u8]>) -> Self { |
There was a problem hiding this comment.
please add a few LiteralMatcher::new unit tests too (\^a, a\$, ^\^, a\\$) :)
There was a problem hiding this comment.
Added one for each of those, \^a, a\$, ^\^ and a\\$, checking both what matches and where.
A pattern with no regex characters goes to the literal matcher. It drops the backslashes first and then looks for
^and$, so an escaped\^or\$turns into an anchor.Same thing with
-E, ands/^a\$/X/matched a plainaline as if it were^a$.LiteralMatcher::newnow takes the raw pattern, picks the anchors off it, and only then removes the escapes. A trailing$counts as an anchor only when an even number of backslashes comes before it, sob\\$still meansb\at the end of the line.Test
test_escaped_anchors_in_literal_patternchecks BRE and ERE cases against GNU sed 4.9. It fails on main and passes with the change.