diff options
-rw-r--r-- | editors/sed.c | 10 | ||||
-rwxr-xr-x | testsuite/sed.tests | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/editors/sed.c b/editors/sed.c index 302a15605..30ab8c9fb 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -936,7 +936,15 @@ static void process_files(void) | |||
936 | /* Skip blocks of commands we didn't match */ | 936 | /* Skip blocks of commands we didn't match */ |
937 | if (sed_cmd->cmd == '{') { | 937 | if (sed_cmd->cmd == '{') { |
938 | if (sed_cmd->invert ? matched : !matched) { | 938 | if (sed_cmd->invert ? matched : !matched) { |
939 | while (sed_cmd->cmd != '}') { | 939 | unsigned nest_cnt = 0; |
940 | while (1) { | ||
941 | if (sed_cmd->cmd == '{') | ||
942 | nest_cnt++; | ||
943 | if (sed_cmd->cmd == '}') { | ||
944 | nest_cnt--; | ||
945 | if (nest_cnt == 0) | ||
946 | break; | ||
947 | } | ||
940 | sed_cmd = sed_cmd->next; | 948 | sed_cmd = sed_cmd->next; |
941 | if (!sed_cmd) | 949 | if (!sed_cmd) |
942 | bb_error_msg_and_die("unterminated {"); | 950 | bb_error_msg_and_die("unterminated {"); |
diff --git a/testsuite/sed.tests b/testsuite/sed.tests index f88524d07..b0de9657c 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests | |||
@@ -253,4 +253,9 @@ testing "sed c" \ | |||
253 | "repl\nrepl\n" "" \ | 253 | "repl\nrepl\n" "" \ |
254 | "first\nsecond\n" | 254 | "first\nsecond\n" |
255 | 255 | ||
256 | testing "sed nested {}s" \ | ||
257 | "sed '/asd/ { p; /s/ { s/s/c/ }; p; q }'" \ | ||
258 | "qwe\nasd\nacd\nacd\n" "" \ | ||
259 | "qwe\nasd\nzxc\n" | ||
260 | |||
256 | exit $FAILCOUNT | 261 | exit $FAILCOUNT |