OSSP CVS Repository

ossp - Check-in [1940]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1940
Date: 2002-Mar-04 13:01:53 (local)
2002-Mar-04 12:01:53 (UTC)
User:rse
Branch:
Comment: Fix regex problem by no longer allowing variables in the pattern part of s/pattern/subst/. Because it is far more common that one needs '$' there instead of a variable.
Tickets:
Inspections:
Files:
ossp-pkg/var/TODO      1.21 -> 1.22     0 inserted, 8 deleted
ossp-pkg/var/var.c      1.76 -> 1.77     21 inserted, 1 deleted
ossp-pkg/var/var.pod      1.25 -> 1.26     2 inserted, 1 deleted
ossp-pkg/var/var_test.c      1.39 -> 1.40     1 inserted, 0 deleted

ossp-pkg/var/TODO 1.21 -> 1.22

--- TODO 2002/03/04 11:54:05     1.21
+++ TODO 2002/03/04 12:01:53     1.22
@@ -1,13 +1,5 @@
                                OSSP var
 
- o problem:
-   ${foo:s/^(.+)$/<\1>/} 
-   -> fails with malformatted search & replace error because
-      it tries to parse the $ as a variable.
-   ${foo:s/^(.+)\$/<\1>/} 
-   -> does not substitute because it leaves the \$ in the regex
-      and this no longer matches the end (instead it matches a dollar)
-
  o "problem"!?:
    ${unknown:-foo} fails on force_expand and results
    in no expansion (kept as is) if not forced_expand.


ossp-pkg/var/var.c 1.76 -> 1.77

--- var.c        2002/03/04 11:53:27     1.76
+++ var.c        2002/03/04 12:01:53     1.77
@@ -447,6 +447,25 @@
 static int parse_numexp (var_t *var, var_parse_t *ctx, const char *begin, const char *end, int *result, int *failed);
 static int parse_name   (var_t *var, var_parse_t *ctx, const char *begin, const char *end);
 
+/* parse pattern text */
+static int 
+parse_pattern(
+    var_t *var, var_parse_t *ctx,
+    const char *begin, const char *end)
+{
+    const char *p;
+
+    /* parse until '/' */
+    for (p = begin; p != end && *p != '/'; p++) {
+        if (*p == var->syntax.escape) {
+            if (p + 1 == end)
+                return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
+            p++;
+        }
+    }
+    return (p - begin);
+}
+
 /* parse substitution text */
 static int 
 parse_substext(
@@ -1283,9 +1302,10 @@
             if (*p != '/')
                 return VAR_ERR_MALFORMATTED_REPLACE;
             p++;
-            rc = parse_substext_or_variable(var, ctx, p, end, &search);
+            rc = parse_pattern(var, ctx, p, end);
             if (rc < 0)
                 goto error_return;
+            tokenbuf_set(&search, p, p + rc, 0);
             p += rc;
             if (*p != '/') {
                 rc = VAR_ERR_MALFORMATTED_REPLACE;


ossp-pkg/var/var.pod 1.25 -> 1.26

--- var.pod      2002/03/04 11:53:27     1.25
+++ var.pod      2002/03/04 12:01:53     1.26
@@ -221,7 +221,7 @@
                | 'o' NUMBER ('-'|',') (NUMBER)?
                | '#'
                | '*' (TEXT_EXP|variable)+
-               | 's' '/' (variable|TEXT_SUBST)+ 
+               | 's' '/' (TEXT_PATTERN)+ 
                      '/' (variable|TEXT_SUBST)* 
                      '/' ('g'|'i'|'t')*
                | 'y' '/' (variable|TEXT_SUBST)+ 
@@ -249,6 +249,7 @@
 
  NUMBER      ::= ('0'|...|'9')+
 
+ TEXT_PATTERN::= (^('/'))+
  TEXT_SUBST  ::= (^(DELIM_INIT|'/'))+
  TEXT_ARGS   ::= (^(DELIM_INIT|')'))+
  TEXT_EXP    ::= (^(DELIM_INIT|DELIM_CLOSE|':'))+


ossp-pkg/var/var_test.c 1.39 -> 1.40

--- var_test.c   2002/03/04 11:53:27     1.39
+++ var_test.c   2002/03/04 12:01:53     1.40
@@ -186,6 +186,7 @@
         { "${HOME:s/E/bla/t}",            "/home/regression-tests"                         },
         { "${HOME:s/E/bla/ti}",           "/hombla/regression-tests"                       },
         { "${HOME:s/E/bla/tig}",          "/hombla/rblagrblassion-tblasts"                 },
+        { "${HOME:s/^(.*)$/<\\1>/}",      "</home/regression-tests>"                       },
         { "${HOME:o1-5}",                 "home/"                                          },
         { "${HOME:o1,5}",                 "home/"                                          },
         { "${HOME:o5,}",                  "/regression-tests"                              },

CVSTrac 2.0.1