Fix a bug that creapt in recently with substitution subprinting, and add
authorGlenn L McGrath <bug1@ihug.co.nz>
Tue, 16 Sep 2003 01:46:36 +0000 (01:46 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Tue, 16 Sep 2003 01:46:36 +0000 (01:46 -0000)
a test for it.

editors/sed.c
testsuite/sed/sed-subst-subprint [new file with mode: 0644]

index da15c4d06d4b419d37b9c8391474532873a00881..a5a9d41a0769629787904ddf0b877c6fa1a52799 100644 (file)
@@ -914,7 +914,6 @@ static void process_file(FILE * file)
 #endif
                                        /* we print the pattern_space once, unless we were told to be quiet */
                                        substituted |= do_subst_command(sed_cmd, &pattern_space);
-
 #ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE
                                        /* undo HACK: escape newlines twice so regex can match them */
                                        {
@@ -930,10 +929,10 @@ static void process_file(FILE * file)
                                                        || (sed_cmd->next->cmd != 's'))) {
                                                force_print = 1;
                                        }
-
                                        /* we also print the line if we were given the 'p' flag
                                         * (this is quite possibly the second printing) */
-                                       if ((sed_cmd->sub_p) && altered) {
+//                                     if ((sed_cmd->sub_p) && (!altered || substituted)) {
+                                       if ((sed_cmd->sub_p) && (altered || substituted)) {
                                                puts(pattern_space);
                                        }
                                        break;
diff --git a/testsuite/sed/sed-subst-subprint b/testsuite/sed/sed-subst-subprint
new file mode 100644 (file)
index 0000000..24f8bad
--- /dev/null
@@ -0,0 +1,9 @@
+busybox sed 's/foo/bar/p'>output <<EOF
+foo
+bar
+EOF
+cmp -s output - <<EOF
+bar
+bar
+bar
+EOF