aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-06-08 10:25:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-06-08 10:25:31 +0200
commit37ca36a71114a6fc5303d33cabc311cd8b9bf19a (patch)
tree28f9108375b2dc4050d447995f3fe497315d3d39
parentba1d561d767a6f05da62adadc798f98118b2a3ee (diff)
downloadbusybox-w32-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.tar.gz
busybox-w32-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.tar.bz2
busybox-w32-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.zip
sed: yet another fix on top of zero length match code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/sed.c15
-rwxr-xr-xtestsuite/sed.tests6
2 files changed, 15 insertions, 6 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 0fe82f337..652aaf573 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -768,8 +768,11 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
768 * Second match is NOT replaced! 768 * Second match is NOT replaced!
769 */ 769 */
770 if (prev_match_empty || start != 0 || start != end) { 770 if (prev_match_empty || start != 0 || start != end) {
771 //dbg("%d %d %d", prev_match_empty, start, end);
771 dbg("inserting replacement at %d in '%s'", start, line); 772 dbg("inserting replacement at %d in '%s'", start, line);
772 do_subst_w_backrefs(line, sed_cmd->string); 773 do_subst_w_backrefs(line, sed_cmd->string);
774 /* Flag that something has changed */
775 altered = 1;
773 } else { 776 } else {
774 dbg("NOT inserting replacement at %d in '%s'", start, line); 777 dbg("NOT inserting replacement at %d in '%s'", start, line);
775 } 778 }
@@ -778,16 +781,18 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
778 * copy verbatim one char after it before attempting more matches 781 * copy verbatim one char after it before attempting more matches
779 */ 782 */
780 prev_match_empty = (start == end); 783 prev_match_empty = (start == end);
781 if (prev_match_empty && line[end]) { 784 if (prev_match_empty) {
782 pipe_putc(line[end]); 785 if (!line[end]) {
783 end++; 786 tried_at_eol = 1;
787 } else {
788 pipe_putc(line[end]);
789 end++;
790 }
784 } 791 }
785 792
786 /* Advance past the match */ 793 /* Advance past the match */
787 dbg("line += %d", end); 794 dbg("line += %d", end);
788 line += end; 795 line += end;
789 /* Flag that something has changed */
790 altered = 1;
791 796
792 /* if we're not doing this globally, get out now */ 797 /* if we're not doing this globally, get out now */
793 if (sed_cmd->which_match != 0) 798 if (sed_cmd->which_match != 0)
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index 12b36ae18..468565f47 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -302,10 +302,14 @@ testing "sed zero chars match/replace advances correctly 2" \
302 "sed 's [^ .]* x g'" \ 302 "sed 's [^ .]* x g'" \
303 "x x.x\n" "" " a.b\n" 303 "x x.x\n" "" " a.b\n"
304 304
305testing "sed zero chars match/replace logic must not falsely trigger here" \ 305testing "sed zero chars match/replace logic must not falsely trigger here 1" \
306 "sed 's/a/A/g'" \ 306 "sed 's/a/A/g'" \
307 "_AAA1AA\n" "" "_aaa1aa\n" 307 "_AAA1AA\n" "" "_aaa1aa\n"
308 308
309testing "sed zero chars match/replace logic must not falsely trigger here 2" \
310 "sed 's/ *$/_/g'" \
311 "qwerty_\n" "" "qwerty\n"
312
309# testing "description" "commands" "result" "infile" "stdin" 313# testing "description" "commands" "result" "infile" "stdin"
310 314
311exit $FAILCOUNT 315exit $FAILCOUNT