Fix s/[/]// handling (noted by Dumas Patrice).
authorMatt Kraai <kraai@debian.org>
Fri, 24 Aug 2001 14:45:50 +0000 (14:45 -0000)
committerMatt Kraai <kraai@debian.org>
Fri, 24 Aug 2001 14:45:50 +0000 (14:45 -0000)
Changelog
editors/sed.c
sed.c

index dc1fdd1fb608a8dc4bf9e51f4fd27ff2ab5aa68a..5e0f5fd4bb2bae3b4977a62dfe95fe62bf5c3291 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -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--
index 4fe882d20366fa8765aff25e4b33e3b441cbf548..989df7cb4be609fa173e7e770db13bd26d8c7c25 100644 (file)
@@ -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/sed.c b/sed.c
index 4fe882d20366fa8765aff25e4b33e3b441cbf548..989df7cb4be609fa173e7e770db13bd26d8c7c25 100644 (file)
--- a/sed.c
+++ b/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;
        }