From 70624846fdfb95ed3913d86cd5e72116791b9070 Mon Sep 17 00:00:00 2001 From: Matt Kraai Date: Fri, 21 Dec 2001 16:04:12 +0000 Subject: [PATCH] Ignore blanks before the first address and before the command. --- editors/sed.c | 8 ++++++++ testsuite/sed/sed-accepts-blanks-before-command | 1 + 2 files changed, 9 insertions(+) create mode 100644 testsuite/sed/sed-accepts-blanks-before-command diff --git a/editors/sed.c b/editors/sed.c index 7f76584..fe1c0db 100644 --- a/editors/sed.c +++ b/editors/sed.c @@ -414,6 +414,10 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd * part1 part2 part3 */ + /* skip initial whitespace */ + while (isspace(cmdstr[idx])) + idx++; + /* first part (if present) is an address: either a number or a /regex/ */ if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/') idx = get_address(sed_cmd, cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match); @@ -422,6 +426,10 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd if (cmdstr[idx] == ',') idx += get_address(sed_cmd, &cmdstr[++idx], &sed_cmd->end_line, &sed_cmd->end_match); + /* skip whitespace before the command */ + while (isspace(cmdstr[idx])) + idx++; + /* last part (mandatory) will be a command */ if (cmdstr[idx] == '\0') error_msg_and_die("missing command"); diff --git a/testsuite/sed/sed-accepts-blanks-before-command b/testsuite/sed/sed-accepts-blanks-before-command new file mode 100644 index 0000000..9597c2f --- /dev/null +++ b/testsuite/sed/sed-accepts-blanks-before-command @@ -0,0 +1 @@ +busybox sed -e '1 d'