sed: fix breakage added by zero length match code
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 7 Jun 2012 14:34:57 +0000 (16:34 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 7 Jun 2012 14:34:57 +0000 (16:34 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c
testsuite/sed.tests

index 85c84665b1ca19cc72440ced0e374db504fff589..0fe82f3376e642d21a47ed779b979abe925a3b0a 100644 (file)
@@ -767,7 +767,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
                 * second is "" before "d", third is "" after "d".
                 * Second match is NOT replaced!
                 */
-               if (prev_match_empty || start != 0) {
+               if (prev_match_empty || start != 0 || start != end) {
                        dbg("inserting replacement at %d in '%s'", start, line);
                        do_subst_w_backrefs(line, sed_cmd->string);
                } else {
index 375beb51839177095b17e435dfd1d64f17dd1041..12b36ae185cd12bcb1bf88cc775a886ed4e139cb 100755 (executable)
@@ -302,6 +302,10 @@ testing "sed zero chars match/replace advances correctly 2" \
        "sed 's [^ .]* x g'" \
        "x x.x\n" "" " a.b\n"
 
+testing "sed zero chars match/replace logic must not falsely trigger here" \
+       "sed 's/a/A/g'" \
+       "_AAA1AA\n" "" "_aaa1aa\n"
+
 # testing "description" "commands" "result" "infile" "stdin"
 
 exit $FAILCOUNT