Skip to content

Commit 870eea8

Browse files
avargitster
authored andcommitted
grep: do not enter PCRE2_UTF mode on fixed matching
As discussed in the last commit partially fix a bug introduced in b65abca ("grep: use PCRE v2 for optimized fixed-string search", 2019-07-01). Because PCRE v2, unlike kwset, validates its UTF-8 input we'd die on e.g.: fatal: pcre2_match failed with error code -22: UTF-8 error: isolated byte with 0x80 bit set When grepping a non-ASCII fixed string. This is a more general problem that's hard to fix, but we can at least fix the most common case of grepping for a fixed string without "-i". I can't think of a reason for why we'd turn on PCRE2_UTF when matching byte-for-byte like that. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a59998 commit 870eea8

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

grep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
472472
}
473473
options |= PCRE2_CASELESS;
474474
}
475-
if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern))
475+
if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern) &&
476+
!(!opt->ignore_case && (p->fixed || p->is_fixed)))
476477
options |= PCRE2_UTF;
477478

478479
p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern,

t/t7812-grep-icase-non-ascii.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep ASCII from invalid UT
6868
'
6969

7070
test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data' '
71-
test_might_fail git grep -h "æ" invalid-0x80 >actual &&
71+
git grep -h "æ" invalid-0x80 >actual &&
7272
test_cmp expected actual &&
73-
test_must_fail git grep -h "(*NO_JIT)æ" invalid-0x80 &&
73+
git grep -h "(*NO_JIT)æ" invalid-0x80 &&
7474
test_cmp expected actual
7575
'
7676

0 commit comments

Comments
 (0)