[git commit master] sed: fix nested {} case
Denys Vlasenko
vda.linux at googlemail.com
Tue Apr 20 08:00:03 UTC 2010
commit: http://git.busybox.net/busybox/commit/?id=f2c16edf99486a0ce2ca57f111831668e77d0fd1
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
editors/sed.c | 10 +++++++++-
testsuite/sed.tests | 5 +++++
2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/editors/sed.c b/editors/sed.c
index 302a156..30ab8c9 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -936,7 +936,15 @@ static void process_files(void)
/* Skip blocks of commands we didn't match */
if (sed_cmd->cmd == '{') {
if (sed_cmd->invert ? matched : !matched) {
- while (sed_cmd->cmd != '}') {
+ unsigned nest_cnt = 0;
+ while (1) {
+ if (sed_cmd->cmd == '{')
+ nest_cnt++;
+ if (sed_cmd->cmd == '}') {
+ nest_cnt--;
+ if (nest_cnt == 0)
+ break;
+ }
sed_cmd = sed_cmd->next;
if (!sed_cmd)
bb_error_msg_and_die("unterminated {");
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index f88524d..b0de965 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -253,4 +253,9 @@ testing "sed c" \
"repl\nrepl\n" "" \
"first\nsecond\n"
+testing "sed nested {}s" \
+ "sed '/asd/ { p; /s/ { s/s/c/ }; p; q }'" \
+ "qwe\nasd\nacd\nacd\n" "" \
+ "qwe\nasd\nzxc\n"
+
exit $FAILCOUNT
--
1.6.3.3
More information about the busybox-cvs
mailing list