diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-02-10 14:48:33 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-02-10 14:48:33 -0800 |
commit | 59ace284f33fe9928fcdb04b02044c921fd6905e (patch) | |
tree | 53840b244e5edc39b90e347ff8c48e6254a0e4b6 /grep.c | |
parent | 0199c68d010b613bde2575cd54d8c3597431fc81 (diff) | |
parent | 95ca1f987edd23389e3079d0a7fe6d0f89927b68 (diff) | |
download | git-59ace284f33fe9928fcdb04b02044c921fd6905e.tar.gz |
Merge branch 'ab/grep-pcre-invalid-utf8'
Update support for invalid UTF-8 in PCRE2.
* ab/grep-pcre-invalid-utf8:
grep/pcre2: better support invalid UTF-8 haystacks
grep/pcre2 tests: don't rely on invalid UTF-8 data test
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -391,7 +391,23 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt } if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern) && !(!opt->ignore_case && (p->fixed || p->is_fixed))) - options |= PCRE2_UTF; + options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF); + + /* Work around https://bugs.exim.org/show_bug.cgi?id=2642 fixed in 10.36 */ + if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS)) { + struct strbuf buf; + int len; + int err; + + if ((len = pcre2_config(PCRE2_CONFIG_VERSION, NULL)) < 0) + BUG("pcre2_config(..., NULL) failed: %d", len); + strbuf_init(&buf, len + 1); + if ((err = pcre2_config(PCRE2_CONFIG_VERSION, buf.buf)) < 0) + BUG("pcre2_config(..., buf.buf) failed: %d", err); + if (versioncmp(buf.buf, "10.36") < 0) + options |= PCRE2_NO_START_OPTIMIZE; + strbuf_release(&buf); + } p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern, p->patternlen, options, &error, &erroffset, |