sed: fix nested {} case
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
96a1833231
commit
f2c16edf99
@ -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 {");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user