diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-12 01:49:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-12 01:49:04 +0200 |
commit | a2215b98f7d65bc613b9c8f008d79672402c6a07 (patch) | |
tree | a522b707160253cba5805279b871cc33dabc24ce | |
parent | 94043e8ad2d30cc2199b35d18c853314ade174a3 (diff) | |
download | busybox-w32-a2215b98f7d65bc613b9c8f008d79672402c6a07.tar.gz busybox-w32-a2215b98f7d65bc613b9c8f008d79672402c6a07.tar.bz2 busybox-w32-a2215b98f7d65bc613b9c8f008d79672402c6a07.zip |
sed: fix a command with multible trailing backslashes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/sed.c | 14 | ||||
-rwxr-xr-x | testsuite/sed.tests | 14 | ||||
-rw-r--r--[-rwxr-xr-x] | testsuite/testing.sh | 2 |
3 files changed, 23 insertions, 7 deletions
diff --git a/editors/sed.c b/editors/sed.c index 30ab8c9fb..4bd6e0168 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -487,7 +487,7 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) | |||
487 | static void add_cmd(const char *cmdstr) | 487 | static void add_cmd(const char *cmdstr) |
488 | { | 488 | { |
489 | sed_cmd_t *sed_cmd; | 489 | sed_cmd_t *sed_cmd; |
490 | int temp; | 490 | unsigned len, n; |
491 | 491 | ||
492 | /* Append this line to any unfinished line from last time. */ | 492 | /* Append this line to any unfinished line from last time. */ |
493 | if (G.add_cmd_line) { | 493 | if (G.add_cmd_line) { |
@@ -496,12 +496,14 @@ static void add_cmd(const char *cmdstr) | |||
496 | cmdstr = G.add_cmd_line = tp; | 496 | cmdstr = G.add_cmd_line = tp; |
497 | } | 497 | } |
498 | 498 | ||
499 | /* If this line ends with backslash, request next line. */ | 499 | /* If this line ends with unescaped backslash, request next line. */ |
500 | temp = strlen(cmdstr); | 500 | n = len = strlen(cmdstr); |
501 | if (temp && cmdstr[--temp] == '\\') { | 501 | while (n && cmdstr[n-1] == '\\') |
502 | n--; | ||
503 | if ((len - n) & 1) { /* if odd number of trailing backslashes */ | ||
502 | if (!G.add_cmd_line) | 504 | if (!G.add_cmd_line) |
503 | G.add_cmd_line = xstrdup(cmdstr); | 505 | G.add_cmd_line = xstrdup(cmdstr); |
504 | G.add_cmd_line[temp] = '\0'; | 506 | G.add_cmd_line[len-1] = '\0'; |
505 | return; | 507 | return; |
506 | } | 508 | } |
507 | 509 | ||
@@ -560,7 +562,7 @@ static void add_cmd(const char *cmdstr) | |||
560 | /* last part (mandatory) will be a command */ | 562 | /* last part (mandatory) will be a command */ |
561 | if (!*cmdstr) | 563 | if (!*cmdstr) |
562 | bb_error_msg_and_die("missing command"); | 564 | bb_error_msg_and_die("missing command"); |
563 | sed_cmd->cmd = *(cmdstr++); | 565 | sed_cmd->cmd = *cmdstr++; |
564 | cmdstr = parse_cmd_args(sed_cmd, cmdstr); | 566 | cmdstr = parse_cmd_args(sed_cmd, cmdstr); |
565 | 567 | ||
566 | /* Add the command to the command array */ | 568 | /* Add the command to the command array */ |
diff --git a/testsuite/sed.tests b/testsuite/sed.tests index b0de9657c..5b0750cac 100755 --- a/testsuite/sed.tests +++ b/testsuite/sed.tests | |||
@@ -258,4 +258,18 @@ testing "sed nested {}s" \ | |||
258 | "qwe\nasd\nacd\nacd\n" "" \ | 258 | "qwe\nasd\nacd\nacd\n" "" \ |
259 | "qwe\nasd\nzxc\n" | 259 | "qwe\nasd\nzxc\n" |
260 | 260 | ||
261 | testing "sed a cmd ended by double backslash" \ | ||
262 | "sed -e '/| one /a \\ | ||
263 | | three \\\\' -e '/| one-/a \\ | ||
264 | | three-* \\\\'" \ | ||
265 | ' | one \\ | ||
266 | | three \\ | ||
267 | | two \\ | ||
268 | ' '' \ | ||
269 | ' | one \\ | ||
270 | | two \\ | ||
271 | ' | ||
272 | |||
273 | # testing "description" "arguments" "result" "infile" "stdin" | ||
274 | |||
261 | exit $FAILCOUNT | 275 | exit $FAILCOUNT |
diff --git a/testsuite/testing.sh b/testsuite/testing.sh index 65a0f6529..913d7f8ef 100755..100644 --- a/testsuite/testing.sh +++ b/testsuite/testing.sh | |||
@@ -73,7 +73,7 @@ testing() | |||
73 | 73 | ||
74 | if [ $# -ne 5 ] | 74 | if [ $# -ne 5 ] |
75 | then | 75 | then |
76 | echo "Test $NAME has wrong number of arguments (must be 5) ($# $*)" >&2 | 76 | echo "Test $NAME has wrong number of arguments: $# (must be 5)" >&2 |
77 | exit 1 | 77 | exit 1 |
78 | fi | 78 | fi |
79 | 79 | ||