3 test_description
='git grep with a binary pattern files'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 nul_match_internal
() {
15 pattern_human
=$
(echo "$pattern" |
sed 's/Q/<NUL>/g')
17 if test "$matches" = 1
19 test_expect_success
$prereqs "LC_ALL='$lc_all' git grep $extra_flags -f f $flags '$pattern_human' a" "
20 printf '$pattern' | q_to_nul >f &&
21 LC_ALL='$lc_all' git grep $extra_flags -f f $flags a
23 elif test "$matches" = 0
25 test_expect_success
$prereqs "LC_ALL='$lc_all' git grep $extra_flags -f f $flags '$pattern_human' a" "
27 printf '$pattern' | q_to_nul >f &&
28 test_must_fail env LC_ALL=\"$lc_all\" git grep $extra_flags -f f $flags a 2>stderr &&
29 test_grep ! 'This is only supported with -P under PCRE v2' stderr
31 elif test "$matches" = P
33 test_expect_success
$prereqs "error, PCRE v2 only: LC_ALL='$lc_all' git grep -f f $flags '$pattern_human' a" "
35 printf '$pattern' | q_to_nul >f &&
36 test_must_fail env LC_ALL=\"$lc_all\" git grep -f f $flags a 2>stderr &&
37 test_grep 'This is only supported with -P under PCRE v2' stderr
40 test_expect_success
"PANIC: Test framework error. Unknown matches value $matches" 'false'
47 matches_pcre2_locale
=$3
50 pattern_human
=$
(echo "$pattern" |
sed 's/Q/<NUL>/g')
52 nul_match_internal
"$matches" "" "C" "" "$flags" "$pattern"
53 nul_match_internal
"$matches_pcre2" "LIBPCRE2" "C" "-P" "$flags" "$pattern"
54 nul_match_internal
"$matches_pcre2_locale" "LIBPCRE2,GETTEXT_LOCALE" "$is_IS_locale" "-P" "$flags" "$pattern"
57 test_expect_success
'setup' "
58 echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
63 # Simple fixed-string matching
64 nul_match P P P
'-F' 'yQf'
65 nul_match P P P
'-F' 'yQx'
66 nul_match P P P
'-Fi' 'YQf'
67 nul_match P P P
'-Fi' 'YQx'
68 nul_match P P
1 '' 'yQf'
69 nul_match P P
0 '' 'yQx'
70 nul_match P P
1 '' 'æQð'
71 nul_match P P P
'-F' 'eQm[*]c'
72 nul_match P P P
'-Fi' 'EQM[*]C'
74 # Regex patterns that would match but shouldn't with -F
75 nul_match P P P
'-F' 'yQ[f]'
76 nul_match P P P
'-F' '[y]Qf'
77 nul_match P P P
'-Fi' 'YQ[F]'
78 nul_match P P P
'-Fi' '[Y]QF'
79 nul_match P P P
'-F' 'æQ[ð]'
80 nul_match P P P
'-F' '[æ]Qð'
82 # Matching pattern and subject case with -i
83 nul_match P
1 1 '-i' '[æ]Qð'
85 # ...PCRE v2 only matches non-ASCII with -i casefolding under UTF-8
87 nul_match P P P
'-Fi' 'ÆQ[Ð]'
88 nul_match P
0 1 '-i' 'ÆQ[Ð]'
89 nul_match P
0 1 '-i' '[Æ]QÐ'
90 nul_match P
0 1 '-i' '[Æ]Qð'
91 nul_match P
0 1 '-i' 'ÆQÐ'
93 # \0 in regexes can only work with -P & PCRE v2
94 nul_match P P
1 '' 'yQ[f]'
95 nul_match P P
1 '' '[y]Qf'
96 nul_match P P
1 '-i' 'YQ[F]'
97 nul_match P P
1 '-i' '[Y]Qf'
98 nul_match P P
1 '' 'æQ[ð]'
99 nul_match P P
1 '' '[æ]Qð'
100 nul_match P P
1 '-i' 'ÆQ[Ð]'
101 nul_match P P
1 '' 'eQm.*cQ'
102 nul_match P P
1 '-i' 'EQM.*cQ'
103 nul_match P P
0 '' 'eQm[*]c'
104 nul_match P P
0 '-i' 'EQM[*]C'
106 # Assert that we're using REG_STARTEND and the pattern doesn't match
107 # just because it's cut off at the first \0.
108 nul_match P P
0 '-i' 'NOMATCHQð'
109 nul_match P P
0 '-i' '[Æ]QNOMATCH'
110 nul_match P P
0 '-i' '[æ]QNOMATCH'
112 # Ensure that the matcher doesn't regress to something that stops at
114 nul_match P P P
'-F' 'yQ[f]'
115 nul_match P P P
'-Fi' 'YQ[F]'
116 nul_match P P
0 '' 'yQNOMATCH'
117 nul_match P P
0 '' 'QNOMATCH'
118 nul_match P P
0 '-i' 'YQNOMATCH'
119 nul_match P P
0 '-i' 'QNOMATCH'
120 nul_match P P P
'-F' 'æQ[ð]'
121 nul_match P P P
'-Fi' 'ÆQ[Ð]'
122 nul_match P P
1 '-i' 'ÆQ[Ð]'
123 nul_match P P
0 '' 'yQNÓMATCH'
124 nul_match P P
0 '' 'QNÓMATCH'
125 nul_match P P
0 '-i' 'YQNÓMATCH'
126 nul_match P P
0 '-i' 'QNÓMATCH'