mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 08:43:19 -04:00
sed: Fix handling of an empty pattern space
Add a regression test. PR: 271791 Obtained from: OpenBSD (1.38 millert) MFC after: 2 weeks
This commit is contained in:
parent
053a988497
commit
5982237f1e
2 changed files with 18 additions and 6 deletions
|
|
@ -436,14 +436,12 @@ substitute(struct s_command *cp)
|
|||
* and at the end of the line, terminate.
|
||||
*/
|
||||
if (match[0].rm_so == match[0].rm_eo) {
|
||||
if (*s == '\0' || *s == '\n')
|
||||
slen = -1;
|
||||
else
|
||||
slen--;
|
||||
if (*s != '\0') {
|
||||
if (slen > 0) {
|
||||
cspace(&SS, s++, 1, APPEND);
|
||||
slen--;
|
||||
le++;
|
||||
}
|
||||
} else
|
||||
slen = -1;
|
||||
lastempty = 1;
|
||||
} else
|
||||
lastempty = 0;
|
||||
|
|
|
|||
|
|
@ -159,6 +159,19 @@ minus_e_body()
|
|||
atf_check -o 'inline:--\nab\n' sed $'1 i\\\n--' a
|
||||
}
|
||||
|
||||
atf_test_case command_D
|
||||
command_D_head()
|
||||
{
|
||||
atf_set "descr" "Test handling of an empty pattern space"
|
||||
}
|
||||
command_D_body()
|
||||
{
|
||||
printf "hello\n\nworld\n" > a
|
||||
|
||||
atf_check -o file:a sed -e 's/^//;P;D' a
|
||||
atf_check -o file:a sed -e 's/^//;$!N;P;D' a
|
||||
}
|
||||
|
||||
atf_init_test_cases()
|
||||
{
|
||||
atf_add_test_case inplace_command_q
|
||||
|
|
@ -169,4 +182,5 @@ atf_init_test_cases()
|
|||
atf_add_test_case hex_subst
|
||||
atf_add_test_case bracket_y
|
||||
atf_add_test_case minus_e
|
||||
atf_add_test_case command_D
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue