3 @@ -936,7 +936,15 @@ static void process_files(void)
4 /* Skip blocks of commands we didn't match */
5 if (sed_cmd->cmd == '{') {
6 if (sed_cmd->invert ? matched : !matched) {
7 - while (sed_cmd->cmd != '}') {
8 + unsigned nest_cnt = 0;
10 + if (sed_cmd->cmd == '{')
12 + if (sed_cmd->cmd == '}') {
17 sed_cmd = sed_cmd->next;
19 bb_error_msg_and_die("unterminated {");
20 @@ -1031,7 +1039,7 @@ static void process_files(void)
22 /* Only triggers on last line of a matching range. */
23 if (!sed_cmd->in_match)
24 - sed_puts(sed_cmd->string, NO_EOL_CHAR);
25 + sed_puts(sed_cmd->string, '\n');
28 /* Read file, append contents to output */
29 --- a/testsuite/sed.tests
30 +++ b/testsuite/sed.tests
31 @@ -248,4 +248,14 @@ testing "sed beginning (^) matches only
40 +testing "sed nested {}s" \
41 + "sed '/asd/ { p; /s/ { s/s/c/ }; p; q }'" \
42 + "qwe\nasd\nacd\nacd\n" "" \