sed: fix /regex/,+N match triggering only once, closes 11871
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 13 May 2019 14:29:34 +0000 (16:29 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 13 May 2019 14:30:39 +0000 (16:30 +0200)
function                                             old     new   delta
process_files                                       2235    2246     +11

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c
testsuite/sed.tests

index bb39de14906e94e66baafefc7c9cf70d13aabd4e..57d3dda161620bbbea12eb6f3d94f25d15c1659b 100644 (file)
@@ -1097,6 +1097,8 @@ static void process_files(void)
                int old_matched, matched;
 
                old_matched = sed_cmd->in_match;
+               if (!old_matched)
+                       sed_cmd->end_line = sed_cmd->end_line_orig;
 
                /* Determine if this command matches this line: */
 
index 675cb4f10f73859bc0e3c6b822f38d41ad7bc2d3..67ff87e9378af38e700eeb3f3d2f5b828ef0a801 100755 (executable)
@@ -361,6 +361,12 @@ testing "sed /regex/,+N{...} addresses work" \
        "" \
        "1\n2\n3\n4\n5\n"
 
+testing "sed /regex/,+N{...} addresses work 2" \
+       "sed -n '/a/,+1 p'" \
+       "a\n1\na\n2\na\n3\n" \
+       "" \
+       "a\n1\nc\nc\na\n2\na\n3\n"
+
 testing "sed /regex/,+N{...} -i works" \
        "cat - >input2; sed /^4/,+2{d} -i input input2; echo \$?; cat input input2; rm input2" \
        "0\n""1\n2\n3\n7\n8\n""1\n2\n7\n8\n" \