aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/sed.c19
-rwxr-xr-xtestsuite/sed.tests6
2 files changed, 11 insertions, 14 deletions
diff --git a/editors/sed.c b/editors/sed.c
index c0d79cc7b..b7add1fb1 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1300,16 +1300,17 @@ static void process_files(void)
1300 case 'n': 1300 case 'n':
1301 if (!G.be_quiet) 1301 if (!G.be_quiet)
1302 sed_puts(pattern_space, last_gets_char); 1302 sed_puts(pattern_space, last_gets_char);
1303 if (next_line) { 1303 if (next_line == NULL) {
1304 free(pattern_space); 1304 /* If no next line, jump to end of script and exit. */
1305 pattern_space = next_line; 1305 goto discard_line;
1306 last_gets_char = next_gets_char;
1307 next_line = get_next_line(&next_gets_char, &last_puts_char);
1308 substituted = 0;
1309 linenum++;
1310 break;
1311 } 1306 }
1312 /* fall through */ 1307 free(pattern_space);
1308 pattern_space = next_line;
1309 last_gets_char = next_gets_char;
1310 next_line = get_next_line(&next_gets_char, &last_puts_char);
1311 substituted = 0;
1312 linenum++;
1313 break;
1313 1314
1314 /* Quit. End of script, end of input. */ 1315 /* Quit. End of script, end of input. */
1315 case 'q': 1316 case 'q':
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index a71f8b1f0..05c00a99b 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -73,13 +73,9 @@ testing "sed t (test/branch clears test bit)" "sed -e 's/a/b/;:loop;t loop'" \
73testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \ 73testing "sed T (!test/branch)" "sed -e 's/a/1/;T notone;p;: notone;p'" \
74 "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n" 74 "1\n1\n1\nb\nb\nc\nc\n" "" "a\nb\nc\n"
75 75
76test x"$SKIP_KNOWN_BUGS" = x"" && {
77# Normal sed end-of-script doesn't print "c" because n flushed the pattern
78# space. If n hits EOF, pattern space is empty when script ends.
79# Query: how does this interact with no newline at EOF?
80testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \ 76testing "sed n (flushes pattern space, terminates early)" "sed -e 'n;p'" \
81 "a\nb\nb\nc\n" "" "a\nb\nc\n" 77 "a\nb\nb\nc\n" "" "a\nb\nc\n"
82} 78
83# non-GNU sed: N does _not_ flush pattern space, therefore c is eaten @ script end 79# non-GNU sed: N does _not_ flush pattern space, therefore c is eaten @ script end
84# GNU sed: N flushes pattern space, therefore c is printed too @ script end 80# GNU sed: N flushes pattern space, therefore c is printed too @ script end
85testing "sed N (flushes pattern space (GNU behavior))" "sed -e 'N;p'" \ 81testing "sed N (flushes pattern space (GNU behavior))" "sed -e 'N;p'" \