All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] grep/pcre2: use PCRE2_UTF even with ASCII patterns
@ 2021-12-18 19:50 René Scharfe
  2021-12-18 19:53 ` [PATCH 2/2] grep/pcre2: factor out literal variable René Scharfe
  2022-01-29 17:25 ` [v2.35.0 regression] some PCRE hangs under UTF-8 locale (was: [PATCH 1/2] grep/pcre2: use PCRE2_UTF even with ASCII patterns) SZEDER Gábor
  0 siblings, 2 replies; 17+ messages in thread
From: René Scharfe @ 2021-12-18 19:50 UTC (permalink / raw)
  To: Git List
  Cc: Hamza Mahfooz, Junio C Hamano,
	Ævar Arnfjörð Bjarmason,
	Carlo Marcelo Arenas Belón, Andreas Schwab

compile_pcre2_pattern() currently uses the option PCRE2_UTF only for
patterns with non-ASCII characters.  Patterns with ASCII wildcards can
match non-ASCII strings, though.  Without that option PCRE2 mishandles
UTF-8 input, though -- it matches parts of multi-byte characters.  Fix
that by using PCRE2_UTF even for ASCII-only patterns.

This is a remake of the reverted ae39ba431a (grep/pcre2: fix an edge
case concerning ascii patterns and UTF-8 data, 2021-10-15).  The change
to the condition and the test are simplified and more targeted.

Original-patch-by: Hamza Mahfooz <someguy@effective-light.com>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 grep.c                          | 2 +-
 t/t7812-grep-icase-non-ascii.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/grep.c b/grep.c
index fe847a0111..5badb6d851 100644
--- a/grep.c
+++ b/grep.c
@@ -382,7 +382,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
 		}
 		options |= PCRE2_CASELESS;
 	}
-	if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern) &&
+	if (!opt->ignore_locale && is_utf8_locale() &&
 	    !(!opt->ignore_case && (p->fixed || p->is_fixed)))
 		options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);

diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh
index e5d1e4ea68..ca3f24f807 100755
--- a/t/t7812-grep-icase-non-ascii.sh
+++ b/t/t7812-grep-icase-non-ascii.sh
@@ -123,4 +123,10 @@ test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: gr
 	test_cmp invalid-0xe5 actual
 '

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

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-02-17 22:56 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-18 19:50 [PATCH 1/2] grep/pcre2: use PCRE2_UTF even with ASCII patterns René Scharfe
2021-12-18 19:53 ` [PATCH 2/2] grep/pcre2: factor out literal variable René Scharfe
2021-12-19 19:37   ` Ævar Arnfjörð Bjarmason
2021-12-20 20:52     ` Junio C Hamano
2021-12-20 22:03       ` Ævar Arnfjörð Bjarmason
2021-12-20 20:53     ` Junio C Hamano
2021-12-20 20:47   ` Junio C Hamano
2022-01-29 17:25 ` [v2.35.0 regression] some PCRE hangs under UTF-8 locale (was: [PATCH 1/2] grep/pcre2: use PCRE2_UTF even with ASCII patterns) SZEDER Gábor
2022-01-30  7:55   ` René Scharfe
2022-01-30  9:04     ` SZEDER Gábor
2022-01-30 13:32       ` René Scharfe
2022-01-31 21:01         ` Ævar Arnfjörð Bjarmason
2022-02-05 17:00           ` René Scharfe
2022-02-06 10:08             ` SZEDER Gábor
2022-02-12 20:46             ` Ævar Arnfjörð Bjarmason
2022-02-17 21:14               ` René Scharfe
2022-02-17 22:56                 ` [v2.35.0 regression] some PCRE hangs under UTF-8 locale Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.