[git commit] sed: fix handling of s/// which has empty matches

Denys Vlasenko vda.linux at googlemail.com
Tue Apr 24 17:21:16 UTC 2012


commit: http://git.busybox.net/busybox/commit/?id=e39afe1fbd6d9f1ad1eea0052a5163572e11a98f
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/sed.c       |    2 +-
 testsuite/sed.tests |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/editors/sed.c b/editors/sed.c
index 4e9babb..429c1ed 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -741,7 +741,7 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
 		 * The match_count check is so not to break
 		 * echo "hi" | busybox sed 's/^/!/g'
 		 */
-		if (!G.regmatch[0].rm_so && !G.regmatch[0].rm_eo && match_count) {
+		if (!G.regmatch[0].rm_so && !G.regmatch[0].rm_eo && match_count && *line) {
 			pipe_putc(*line++);
 			continue;
 		}
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index ba163e9..9fa8e19 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -48,6 +48,7 @@ testing "sed accepts multiple -e" "sed -e 'i\' -e '1' -e 'a\' -e '3'" \
 
 # substitutions
 testing "sed -n" "sed -n -e s/foo/bar/ -e s/bar/baz/" "" "" "foo\n"
+testing "sed with empty match" "sed 's/z*//g'" "string\n" "" "string\n"
 testing "sed s//p" "sed -e s/foo/bar/p -e s/bar/baz/p" "bar\nbaz\nbaz\n" \
 	"" "foo\n"
 testing "sed -n s//p" "sed -ne s/abc/def/p" "def\n" "" "abc\n"


More information about the busybox-cvs mailing list