Skip to content

Commit c91b0b7

Browse files
committed
Merge branch 'rs/pcre2-utf'
"git grep --perl-regexp" failed to match UTF-8 characters with wildcard when the pattern consists only of ASCII letters, which has been corrected. * rs/pcre2-utf: grep/pcre2: factor out literal variable grep/pcre2: use PCRE2_UTF even with ASCII patterns
2 parents 5d522cd + 32e3e8b commit c91b0b7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
362362
int jitret;
363363
int patinforet;
364364
size_t jitsizearg;
365+
int literal = !opt->ignore_case && (p->fixed || p->is_fixed);
365366

366367
/*
367368
* Call pcre2_general_context_create() before calling any
@@ -382,8 +383,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
382383
}
383384
options |= PCRE2_CASELESS;
384385
}
385-
if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern) &&
386-
!(!opt->ignore_case && (p->fixed || p->is_fixed)))
386+
if (!opt->ignore_locale && is_utf8_locale() && !literal)
387387
options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
388388

389389
#ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@ test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: gr
123123
test_cmp invalid-0xe5 actual
124124
'
125125

126+
test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-literal ASCII from UTF-8' '
127+
git grep --perl-regexp -h -o -e ll. file >actual &&
128+
echo "lló" >expected &&
129+
test_cmp expected actual
130+
'
131+
126132
test_done

0 commit comments

Comments
 (0)