diff options
-rw-r--r-- | Changelog | 2 | ||||
-rw-r--r-- | editors/sed.c | 15 | ||||
-rw-r--r-- | sed.c | 15 |
3 files changed, 30 insertions, 2 deletions
@@ -15,6 +15,8 @@ -- a whole bunch of ash size optimizations * Rodney Brown <RDBrown@mira.net> -- Optimized gzip.c, shrinking it be ~1.5k + * Matt Kraai + -- Fix sed s/[/]// handling (closes: #1208). -Erik Andersen, --not yet released-- diff --git a/editors/sed.c b/editors/sed.c index 4fe882d..989df7c 100644 --- a/editors/sed.c +++ b/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; } @@ -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; } |