aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-04-20 04:00:03 -0400
committerDenys Vlasenko <vda.linux@googlemail.com>2010-04-20 04:00:03 -0400
commitf2c16edf99486a0ce2ca57f111831668e77d0fd1 (patch)
tree67789d2c4afa727c52db4573b26b50d6c5253ac5
parent96a18332316568ebccaa186ffb519b48c4310714 (diff)
downloadbusybox-w32-f2c16edf99486a0ce2ca57f111831668e77d0fd1.tar.gz
busybox-w32-f2c16edf99486a0ce2ca57f111831668e77d0fd1.tar.bz2
busybox-w32-f2c16edf99486a0ce2ca57f111831668e77d0fd1.zip
sed: fix nested {} case
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/sed.c10
-rwxr-xr-xtestsuite/sed.tests5
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
256testing "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
256exit $FAILCOUNT 261exit $FAILCOUNT