9842cc86b0d68cef257f5f9a78d595c54451b1fb
[openwrt.git] / package / busybox / patches / 000-upstream-sed.patch
1 --- a/editors/sed.c
2 +++ b/editors/sed.c
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;
9 + while (1) {
10 + if (sed_cmd->cmd == '{')
11 + nest_cnt++;
12 + if (sed_cmd->cmd == '}') {
13 + nest_cnt--;
14 + if (nest_cnt == 0)
15 + break;
16 + }
17 sed_cmd = sed_cmd->next;
18 if (!sed_cmd)
19 bb_error_msg_and_die("unterminated {");
20 @@ -1031,7 +1039,7 @@ static void process_files(void)
21 case 'c':
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');
26 goto discard_line;
27
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
32 ">/usr</>lib<\n" "" \
33 "/usr/lib\n"
34
35 +testing "sed c" \
36 + "sed 'crepl'" \
37 + "repl\nrepl\n" "" \
38 + "first\nsecond\n"
39 +
40 +testing "sed nested {}s" \
41 + "sed '/asd/ { p; /s/ { s/s/c/ }; p; q }'" \
42 + "qwe\nasd\nacd\nacd\n" "" \
43 + "qwe\nasd\nzxc\n"
44 +
45 exit $FAILCOUNT
This page took 0.035899 seconds and 3 git commands to generate.