sed: n cmd must reset "we had successful subst" flag. closes bug 1214.
authorDenis Vlasenko <vda.linux@googlemail.com>
Thu, 28 Feb 2008 17:59:01 +0000 (17:59 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Thu, 28 Feb 2008 17:59:01 +0000 (17:59 -0000)
editors/sed.c
testsuite/sed.tests

index e55bcafc441e595f61c0ac39292cd672b7f97c46..c2b9e94b63034ba53969c3089ab773859c8f638a 100644 (file)
@@ -865,7 +865,7 @@ static void process_files(void)
        next_line = get_next_line(&next_gets_char);
 
        /* go through every line in each file */
-again:
+ again:
        substituted = 0;
 
        /* Advance to next line.  Stop if out of lines. */
@@ -877,7 +877,7 @@ again:
         * the '$' address */
        next_line = get_next_line(&next_gets_char);
        linenum++;
-restart:
+ restart:
        /* for every line, go through all the commands */
        for (sed_cmd = G.sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) {
                int old_matched, matched;
@@ -1053,6 +1053,7 @@ restart:
                                        pattern_space = next_line;
                                        last_gets_char = next_gets_char;
                                        next_line = get_next_line(&next_gets_char);
+                                       substituted = 0;
                                        linenum++;
                                        break;
                                }
index 7471ed5fc8286e7fbb991231298b4fb3626d4fcf..4cdbaa687e4fe9fde4f88719d90ba4bd39b61d06 100755 (executable)
@@ -201,4 +201,10 @@ testing "sed s/xxx/[/" "sed -e 's/xxx/[/'" "[\n" "" "xxx\n"
 #testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \
 #      "" "12345"
 
+# testing "description" "arguments" "result" "infile" "stdin"
+
+testing "sed n command must reset 'substituted' bit" \
+       "sed 's/1/x/;T;n;: next;s/3/y/;t quit;n;b next;: quit;q'" \
+       "0\nx\n2\ny\n" "" "0\n1\n2\n3\n"
+
 exit $FAILCOUNT