Repository navigation
grep: treat anchors as whole-record delimiters under -z - #258
yunusarda-sudo wants to merge 1 commit into
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #258 +/- ##
==========================================
- Coverage 97.22% 96.83% -0.39%
==========================================
Files 6 6
Lines 2270 2340 +70
Branches 245 260 +15
==========================================
+ Hits 2207 2266 +59
- Misses 63 73 +10
- Partials 0 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:
|
|
GNU grep testsuite comparison: |
Fixes #195
Summary
With
-z / --null-data, records are delimited by ASCII NUL (\0) and newline is ordinary data inside the record. In GNU grep,^and$anchor strictly to the record boundaries rather than matching next to an embedded newline or before a trailing newline.In Oniguruma:
RegexOptions::REGEX_OPTION_SINGLELINEcompiles^toANCR_BEGIN_BUF(strictly record start), but compiles$toANCR_SEMI_END_BUF.ANCR_SEMI_END_BUFmatches before a trailing newline\nat the end of the buffer (min_semi_end = pre_endifONIGENC_IS_MBC_NEWLINE). Consequently,beta$matchedalpha\nbeta\nunder-z.$anchors strictly to the end of the record buffer (\z/ANCR_END_BUF), not before a trailing\n.Changes
SyntaxOperator::SYNTAX_OPERATOR_ESC_AZ_BUF_ANCHORwhenconfig.null_datais active across regex modes.normalize_null_data_dollar(pattern, mode)which normalizes unescaped$outside bracket expressions to\z(in BRE, only when at the end of the pattern or before subexpression end\)or\|).tests/test_grep.rscovering BRE, ERE, and PCRE anchor semantics on null-terminated records with and without trailing newlines, as well as preserving literal\$and[$].