sed: support back-references in byte mode - #545
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #545 +/- ##
==========================================
- Coverage 83.04% 82.42% -0.62%
==========================================
Files 13 13
Lines 7046 7170 +124
Branches 401 404 +3
==========================================
+ Hits 5851 5910 +59
- Misses 1192 1257 +65
Partials 3 3
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 degrade performance by 0.87%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
|
could you please add more tests? the code coverage isn't ideal: |
|
Added five focused unit tests in 51aaf56 covering non-ASCII byte offset mapping, optional capture groups, multiple invalid UTF-8 matches, zero-width iteration, and no-match paths. Locally, |
Closes #543.
Problem
Byte mode rejected every regular expression containing a back-reference before attempting a match. This made address and substitution expressions such as
\(a\)b\1fail whenever theClocale selected byte-oriented matching.User impact
Scripts using back-references could work in a UTF-8 locale but fail immediately in the
Clocale. Invalid UTF-8 input could not use back-references at all.Root cause
The fast byte regex engine does not implement back-references, while the fallback
fancy_regexengine accepts only UTF-8 text and reports UTF-8 offsets.Fix
fancy_regexpath that maps each input byte to one Unicode scalarcaptures_iterstreaming instead of collecting every matchVerification
cargo test --lib— 360 passedcargo test backref— 9 related tests passedcargo clippy --lib --tests -- -D warningscargo fmt --all -- --checkThe full integration run on Windows reached 219 passing tests, 2 ignored tests, and 47 failures caused by existing CRLF-sensitive shell-script and fixture expectations. The focused integration tests for this change pass.
AI disclosure
AI assistance was used to help trace the byte/UTF-8 boundary, implement the offset mapping, and draft tests. The resulting code was reviewed and verified with the commands above.