From 0ceee5c382fe8f5df49dee1b2f3a148740a280aa Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 24 Sep 2022 19:39:44 -0500 Subject: [PATCH] Fix some sed -z cases and add tests. --- tests/sed.test | 3 +++ toys/posix/sed.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/sed.test b/tests/sed.test index 9b8c2aa5..269012df 100755 --- a/tests/sed.test +++ b/tests/sed.test @@ -175,6 +175,9 @@ testcmd '-z N' '-z N' 'one\0two\0' '' 'one\0two\0' testcmd 'p noeol' '-z p' 'one\0one' '' 'one' testcmd '-z N noeol' '-z N' 'one\0two' '' 'one\0two' testcmd '-z S' "-z 'N;P'" 'one\0one\0two' '' 'one\0two' +testcmd '-z D' "-z 'N;D'" 'two' '' 'one\0two' +testcmd '-z G' "-z 'h;G'" 'one\0one' '' 'one' +testcmd '-z H' "-z 'H;g'" '\0one' '' 'one' # toybox handling of empty capturing groups broke minjail. Check that we # correctly replace an empty capturing group with the empty string: diff --git a/toys/posix/sed.c b/toys/posix/sed.c index 459e9a54..70fe0b2f 100644 --- a/toys/posix/sed.c +++ b/toys/posix/sed.c @@ -330,7 +330,7 @@ static void sed_line(char **pline, long plen) } else if (c=='D') { // Delete up to \n or end of buffer str = line; - while ((str-line)