Fix a bug that creapt in recently with substitution subprinting, and add

a test for it.
This commit is contained in:
Glenn L McGrath 2003-09-16 01:46:36 +00:00
parent 96fd1b98f1
commit 204ff1cea4
2 changed files with 11 additions and 3 deletions

View File

@ -914,7 +914,6 @@ static void process_file(FILE * file)
#endif #endif
/* we print the pattern_space once, unless we were told to be quiet */ /* we print the pattern_space once, unless we were told to be quiet */
substituted |= do_subst_command(sed_cmd, &pattern_space); substituted |= do_subst_command(sed_cmd, &pattern_space);
#ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE #ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE
/* undo HACK: escape newlines twice so regex can match them */ /* 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'))) { || (sed_cmd->next->cmd != 's'))) {
force_print = 1; force_print = 1;
} }
/* we also print the line if we were given the 'p' flag /* we also print the line if we were given the 'p' flag
* (this is quite possibly the second printing) */ * (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); puts(pattern_space);
} }
break; break;

View File

@ -0,0 +1,9 @@
busybox sed 's/foo/bar/p'>output <<EOF
foo
bar
EOF
cmp -s output - <<EOF
bar
bar
bar
EOF