Fix the following testcase by disabling global substitution if the regex
authorGlenn L McGrath <bug1@ihug.co.nz>
Sat, 13 Sep 2003 15:12:22 +0000 (15:12 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Sat, 13 Sep 2003 15:12:22 +0000 (15:12 -0000)
is anchored to the start of line, there can be only one subst.
echo "aah" | sed 's/^a/b/g'

editors/sed.c

index 5bfe924a513a6575ad9af4ab07f7211871dee34c..75ed53eb734a614b0e34a29f2fec3a7bf91a2500 100644 (file)
        Unsupported features:
 
         - GNU extensions
-        - and lots, lots more.
+        - and more.
 
        Bugs:
        
-        - Cant subst globally using ^ or $ in regex, eg. "aah" | sed 's/^a/b/g'
+        - lots
 
        Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html
 */
@@ -299,7 +299,9 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, const char *substr)
        while (substr[++idx]) {
                switch (substr[idx]) {
                case 'g':
-                       sed_cmd->sub_g = 1;
+                       if (match[0] != '^') {
+                               sed_cmd->sub_g = 1;
+                       }
                        break;
                        /* Hmm, i dont see the I option mentioned in the standard */
                case 'I':