From b7090fda302d8ec024dfe456503d6c687deb0f14 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 3 Sep 2001 19:16:23 +0000 Subject: [PATCH] Backport sed fix for s/[/]// handling from Matt Kraai --- busybox/editors/sed.c | 15 ++++++++++++++- busybox/sed.c | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/busybox/editors/sed.c b/busybox/editors/sed.c index 4fe882d20..989df7cb4 100644 --- a/busybox/editors/sed.c +++ b/busybox/editors/sed.c @@ -144,8 +144,21 @@ static void destroy_cmd_strs() */ static int index_of_next_unescaped_regexp_delim(struct sed_cmd *sed_cmd, const char *str, int idx) { + int bracket = -1; + int escaped = 0; + for ( ; str[idx]; idx++) { - if (str[idx] == sed_cmd->delimiter && str[idx-1] != '\\') + if (bracket != -1) { + if (str[idx] == ']' && !(bracket == idx - 1 || + (bracket == idx - 2 && str[idx-1] == '^'))) + bracket = -1; + } else if (escaped) + escaped = 0; + else if (str[idx] == '\\') + escaped = 1; + else if (str[idx] == '[') + bracket = idx; + else if (str[idx] == sed_cmd->delimiter) return idx; } diff --git a/busybox/sed.c b/busybox/sed.c index 4fe882d20..989df7cb4 100644 --- a/busybox/sed.c +++ b/busybox/sed.c @@ -144,8 +144,21 @@ static void destroy_cmd_strs() */ static int index_of_next_unescaped_regexp_delim(struct sed_cmd *sed_cmd, const char *str, int idx) { + int bracket = -1; + int escaped = 0; + for ( ; str[idx]; idx++) { - if (str[idx] == sed_cmd->delimiter && str[idx-1] != '\\') + if (bracket != -1) { + if (str[idx] == ']' && !(bracket == idx - 1 || + (bracket == idx - 2 && str[idx-1] == '^'))) + bracket = -1; + } else if (escaped) + escaped = 0; + else if (str[idx] == '\\') + escaped = 1; + else if (str[idx] == '[') + bracket = idx; + else if (str[idx] == sed_cmd->delimiter) return idx; } -- 2.25.1