grep: drop support for \0 in --fixed-strings <pattern>

Change "-f <file>" to not support patterns with a NUL-byte in them under --fixed-strings. We'll now only support these under "--perl-regexp" with PCRE v2. A previous change to grep's documentation changed the description of "-f <file>" to be vague enough as to not promise that this would work. By dropping support for this we make it a whole lot easier to move away from the kwset backend, which we'll do in a subsequent change. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 1, 2019 at 23:20 UTC 45d1f37ccc16ad53303910e150f7fbe36213aad8
2 files changed +44 -44
grep.c
+3 -3
@@ -644,6 +644,9 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
644 p->word_regexp = opt->word_regexp;
645 p->ignore_case = opt->ignore_case;
646
647 + if (memchr(p->pattern, 0, p->patternlen) && !opt->pcre2)
648 + die(_("given pattern contains NULL byte (via -f <file>). This is only supported with -P under PCRE v2"));
649 +
650 /*
651 * Even when -F (fixed) asks us to do a non-regexp search, we
652 * may not be able to correctly case-fold when -i
@@ -666,9 +669,6 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
669 return;
670 }
671
669 - if (memchr(p->pattern, 0, p->patternlen) && !opt->pcre2)
670 - die(_("given pattern contains NULL byte (via -f <file>). This is only supported with -P under PCRE v2"));
671 -
672 if (opt->fixed) {
673 /*
674 * We come here when the pattern has the non-ascii
t/t7816-grep-binary-pattern.sh
+41 -41
@@ -60,23 +60,23 @@ test_expect_success 'setup' "
60 "
61
62 # Simple fixed-string matching that can use kwset (no -i && non-ASCII)
63 -nul_match 1 1 1 '-F' 'yQf'
64 -nul_match 0 0 0 '-F' 'yQx'
65 -nul_match 1 1 1 '-Fi' 'YQf'
66 -nul_match 0 0 0 '-Fi' 'YQx'
67 -nul_match 1 1 1 '' 'yQf'
68 -nul_match 0 0 0 '' 'yQx'
69 -nul_match 1 1 1 '' 'æQð'
70 -nul_match 1 1 1 '-F' 'eQm[*]c'
71 -nul_match 1 1 1 '-Fi' 'EQM[*]C'
63 +nul_match P P P '-F' 'yQf'
64 +nul_match P P P '-F' 'yQx'
65 +nul_match P P P '-Fi' 'YQf'
66 +nul_match P P P '-Fi' 'YQx'
67 +nul_match P P 1 '' 'yQf'
68 +nul_match P P 0 '' 'yQx'
69 +nul_match P P 1 '' 'æQð'
70 +nul_match P P P '-F' 'eQm[*]c'
71 +nul_match P P P '-Fi' 'EQM[*]C'
72
73 # Regex patterns that would match but shouldn't with -F
74 -nul_match 0 0 0 '-F' 'yQ[f]'
75 -nul_match 0 0 0 '-F' '[y]Qf'
76 -nul_match 0 0 0 '-Fi' 'YQ[F]'
77 -nul_match 0 0 0 '-Fi' '[Y]QF'
78 -nul_match 0 0 0 '-F' 'æQ[ð]'
79 -nul_match 0 0 0 '-F' '[æ]Qð'
74 +nul_match P P P '-F' 'yQ[f]'
75 +nul_match P P P '-F' '[y]Qf'
76 +nul_match P P P '-Fi' 'YQ[F]'
77 +nul_match P P P '-Fi' '[Y]QF'
78 +nul_match P P P '-F' 'æQ[ð]'
79 +nul_match P P P '-F' '[æ]Qð'
80
81 # The -F kwset codepath can't handle -i && non-ASCII...
82 nul_match P 1 1 '-i' '[æ]Qð'
@@ -90,38 +90,38 @@ nul_match P 0 1 '-i' '[Æ]Qð'
90 nul_match P 0 1 '-i' 'ÆQÐ'
91
92 # \0 in regexes can only work with -P & PCRE v2
93 -nul_match P 1 1 '' 'yQ[f]'
94 -nul_match P 1 1 '' '[y]Qf'
95 -nul_match P 1 1 '-i' 'YQ[F]'
96 -nul_match P 1 1 '-i' '[Y]Qf'
97 -nul_match P 1 1 '' 'æQ[ð]'
98 -nul_match P 1 1 '' '[æ]Qð'
99 -nul_match P 0 1 '-i' 'ÆQ[Ð]'
100 -nul_match P 1 1 '' 'eQm.*cQ'
101 -nul_match P 1 1 '-i' 'EQM.*cQ'
102 -nul_match P 0 0 '' 'eQm[*]c'
103 -nul_match P 0 0 '-i' 'EQM[*]C'
93 +nul_match P P 1 '' 'yQ[f]'
94 +nul_match P P 1 '' '[y]Qf'
95 +nul_match P P 1 '-i' 'YQ[F]'
96 +nul_match P P 1 '-i' '[Y]Qf'
97 +nul_match P P 1 '' 'æQ[ð]'
98 +nul_match P P 1 '' '[æ]Qð'
99 +nul_match P P 1 '-i' 'ÆQ[Ð]'
100 +nul_match P P 1 '' 'eQm.*cQ'
101 +nul_match P P 1 '-i' 'EQM.*cQ'
102 +nul_match P P 0 '' 'eQm[*]c'
103 +nul_match P P 0 '-i' 'EQM[*]C'
104
105 # Assert that we're using REG_STARTEND and the pattern doesn't match
106 # just because it's cut off at the first \0.
107 -nul_match 0 0 0 '-i' 'NOMATCHQð'
108 -nul_match P 0 0 '-i' '[Æ]QNOMATCH'
109 -nul_match P 0 0 '-i' '[æ]QNOMATCH'
107 +nul_match P P 0 '-i' 'NOMATCHQð'
108 +nul_match P P 0 '-i' '[Æ]QNOMATCH'
109 +nul_match P P 0 '-i' '[æ]QNOMATCH'
110
111 # Ensure that the matcher doesn't regress to something that stops at
112 # \0
113 -nul_match 0 0 0 '-F' 'yQ[f]'
114 -nul_match 0 0 0 '-Fi' 'YQ[F]'
115 -nul_match 0 0 0 '' 'yQNOMATCH'
116 -nul_match 0 0 0 '' 'QNOMATCH'
117 -nul_match 0 0 0 '-i' 'YQNOMATCH'
118 -nul_match 0 0 0 '-i' 'QNOMATCH'
119 -nul_match 0 0 0 '-F' 'æQ[ð]'
113 +nul_match P P P '-F' 'yQ[f]'
114 +nul_match P P P '-Fi' 'YQ[F]'
115 +nul_match P P 0 '' 'yQNOMATCH'
116 +nul_match P P 0 '' 'QNOMATCH'
117 +nul_match P P 0 '-i' 'YQNOMATCH'
118 +nul_match P P 0 '-i' 'QNOMATCH'
119 +nul_match P P P '-F' 'æQ[ð]'
120 nul_match P P P '-Fi' 'ÆQ[Ð]'
121 -nul_match P 0 1 '-i' 'ÆQ[Ð]'
122 -nul_match 0 0 0 '' 'yQNÓMATCH'
123 -nul_match 0 0 0 '' 'QNÓMATCH'
124 -nul_match 0 0 0 '-i' 'YQNÓMATCH'
125 -nul_match 0 0 0 '-i' 'QNÓMATCH'
121 +nul_match P P 1 '-i' 'ÆQ[Ð]'
122 +nul_match P P 0 '' 'yQNÓMATCH'
123 +nul_match P P 0 '' 'QNÓMATCH'
124 +nul_match P P 0 '-i' 'YQNÓMATCH'
125 +nul_match P P 0 '-i' 'QNÓMATCH'
126
127 test_done