grep: properly switch EOL indicator with -z
-z is supposed to use only the NUL byte as EOL, but we were inadvertently using both newline and NUL due to REG_NEWLINE in cflags. The odds of anyone relying on this bsdgrep-specific bug are quite low, so let's just fix it. At least one port in the wild has been reported to expect the intended behavior. Reported by: Hill Ma <maahiuzeon@gmail.com> Triaged by: the self-proclaimed peanut gallery on Discord
This commit is contained in:
parent
eb03c1f81c
commit
e898a3af97
@ -562,6 +562,7 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
case 'z':
|
||||
fileeol = '\0';
|
||||
cflags &= ~REG_NEWLINE;
|
||||
break;
|
||||
case BIN_OPT:
|
||||
if (strcasecmp("binary", optarg) == 0)
|
||||
|
@ -92,9 +92,22 @@ gnuext_body()
|
||||
|
||||
}
|
||||
|
||||
atf_test_case zflag
|
||||
zflag_body()
|
||||
{
|
||||
|
||||
# The -z flag should pick up 'foo' and 'bar' as on the same line with
|
||||
# 'some kind of junk' in between; a bug was present that instead made
|
||||
# it process this incorrectly.
|
||||
printf "foo\nbar\0" > in
|
||||
|
||||
atf_check grep -qz "foo.*bar" in
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case grep_r_implied
|
||||
atf_add_test_case rgrep
|
||||
atf_add_test_case gnuext
|
||||
atf_add_test_case zflag
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user