Skip to content

Commit 45d1f37

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2575412 commit 45d1f37

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

grep.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
644644
p->word_regexp = opt->word_regexp;
645645
p->ignore_case = opt->ignore_case;
646646

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+
647650
/*
648651
* Even when -F (fixed) asks us to do a non-regexp search, we
649652
* 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)
666669
return;
667670
}
668671

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-
672672
if (opt->fixed) {
673673
/*
674674
* We come here when the pattern has the non-ascii

t/t7816-grep-binary-pattern.sh

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ test_expect_success 'setup' "
6060
"
6161

6262
# 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'
7272

7373
# 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ð'
8080

8181
# The -F kwset codepath can't handle -i && non-ASCII...
8282
nul_match P 1 1 '-i' '[æ]Qð'
@@ -90,38 +90,38 @@ nul_match P 0 1 '-i' '[Æ]Qð'
9090
nul_match P 0 1 '-i' 'ÆQÐ'
9191

9292
# \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'
104104

105105
# Assert that we're using REG_STARTEND and the pattern doesn't match
106106
# 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'
110110

111111
# Ensure that the matcher doesn't regress to something that stops at
112112
# \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[ð]'
120120
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'
126126

127127
test_done

0 commit comments

Comments
 (0)