sed: fix handling of s/// which has empty matches
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 24 Apr 2012 17:21:16 +0000 (19:21 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 24 Apr 2012 17:21:16 +0000 (19:21 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/sed.c
testsuite/sed.tests

index 4e9babb9d02f63dbc46a0d0a4b8059c4d432653f..429c1ed58578d04249d22d54fd7bef42f3455f96 100644 (file)
@@ -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;
                }
index ba163e9e92ecad29f2b341b4386213b923484d82..9fa8e190c53ec1ce0a589ecbe463a773921f13b9 100755 (executable)
@@ -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"