Skip to content

Commit 12fc32f

Browse files
avargitster
authored andcommitted
grep: prepare for testing binary regexes containing rx metacharacters
Add setup code needed for testing regexes that contain both binary data and regex metacharacters. The POSIX regcomp() function inherently can't support that, because it takes a \0-delimited char *, but other regex engines APIs like PCRE v2 take a pattern/length pair, and are thus able to handle \0s in patterns as well as any other character. When kwset was imported in commit 9ecedde ("Use kwset in grep", 2011-08-21) this limitation was fixed, but at the expense of introducing the undocumented limitation that any pattern containing \0 implicitly becomes a fixed match (equivalent to -F having been provided). That's not something we'd like to keep in the future. The inability to match patterns containing \0 is a leaky implementation detail. So add tests as a first step towards changing that. In order to test that \0-patterns can properly match as regexes the test string needs to have some regex metacharacters in it. There were other blind spots in the tests. The code around kwset specially handles case-insensitive & non-ASCII data, but there were no tests for this. Fix all of that by amending the text being matched to contain both regex metacharacters & non-ASCII data. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77f6f44 commit 12fc32f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

t/t7008-grep-binary.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ nul_match () {
2828
}
2929

3030
test_expect_success 'setup' "
31-
echo 'binaryQfile' | q_to_nul >a &&
31+
echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
3232
git add a &&
3333
git commit -m.
3434
"
@@ -162,7 +162,7 @@ test_expect_success 'grep does not honor textconv' '
162162
'
163163

164164
test_expect_success 'grep --textconv honors textconv' '
165-
echo "a:binaryQfile" >expect &&
165+
echo "a:binaryQfileQm[*]cQ*æQð" >expect &&
166166
git grep --textconv Qfile >actual &&
167167
test_cmp expect actual
168168
'
@@ -172,7 +172,7 @@ test_expect_success 'grep --no-textconv does not honor textconv' '
172172
'
173173

174174
test_expect_success 'grep --textconv blob honors textconv' '
175-
echo "HEAD:a:binaryQfile" >expect &&
175+
echo "HEAD:a:binaryQfileQm[*]cQ*æQð" >expect &&
176176
git grep --textconv Qfile HEAD:a >actual &&
177177
test_cmp expect actual
178178
'

0 commit comments

Comments
 (0)