]> err.no Git - varnish/commitdiff
NB: FLAGDAY!
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 11:58:25 +0000 (11:58 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 11:58:25 +0000 (11:58 +0000)
Make an executive decision, and change the regsub() replacement specifiers to
get something which is consistent and nontroubling for URL and query strings.

Since $ and & both are heavily used in query strings, we (DES & I)
have chosen to use \0 ... \9 for replacement indicators, with \0
being the "all matched text" replacement and \1...\9 replacing
with tne N'th paranthesized subexpressions.

   regsub("_barf_", "(b)(a)(r)(f)", "\0\4\3\2\\p") -> "_barffra\p_"

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2741 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_vrt_re.c
varnish-cache/bin/varnishtest/tests/c00001.vtc

index 884203261003cf1cc52cddaf4173edfbc7053cf4..08de0b4498083e4216286bc089ba96bdfd32d872 100644 (file)
@@ -131,20 +131,17 @@ VRT_regsub(const struct sess *sp, int all, const char *str, void *re, const char
                Tadd(&res, str, pm[0].rm_so);
 
                for (s = sub ; *s != '\0'; s++ ) {
-                       if (*s == '\\') {
+                       if (*s != '\\' || s[1] == '\0') {
                                if (res.b < res.e)
-                                       *res.b++ = *++s;
-                       } else if (*s == '&') {
-                               l = pm[0].rm_eo - pm[0].rm_so;
-                               Tadd(&res, str + pm[0].rm_so, l);
-                       } else if (*s == '$' && s[1] == '$') {
-                               l = pm[0].rm_eo - pm[0].rm_so;
-                               Tadd(&res, str + pm[0].rm_so, l);
-                               s++;
-                       } else if (*s == '$' && isdigit(s[1])) {
-                               x = digittoint(*++s);
+                                       *res.b++ = *s;
+                               continue;
+                       }
+                       s++;
+                       if (isdigit(*s)) {
+                               x = digittoint(*s);
                                l = pm[x].rm_eo - pm[x].rm_so;
                                Tadd(&res, str + pm[x].rm_so, l);
+                               continue;
                        } else {
                                if (res.b < res.e)
                                        *res.b++ = *s;
index fa634a9a92bbe1742cf906b1d1059a4c151b0c4d..3db9bdfb6592feb3020fa6534bfee29cf375ae77 100644 (file)
@@ -5,22 +5,24 @@ test "Test VCL regsub()"
 server s1 {
        rxreq 
        txresp \
-               -hdr "Foobar: barf" \
+               -hdr "Foobar: _barf_" \
                -hdr "Connection: close" \
                -body "012345\n"
 }
 
 varnish v1 -vcl+backend { 
        sub vcl_fetch {
-               set obj.http.Snafu1 = regsub(obj.http.Foobar, "ar", "&&");
+               set obj.http.Snafu1 = regsub(obj.http.Foobar, "ar", "\0\0");
                set obj.http.Snafu2 =
-                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "$4$3$2p");
+                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "\4\3\2p");
                set obj.http.Snafu3 =
-                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "$4\$$3$2p");
+                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "\4\\\3\2p");
                set obj.http.Snafu4 =
-                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "$4\&$3$2p");
+                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "\4\&\3\2p");
                set obj.http.Snafu5 =
-                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "$$$4$3$2\$p");
+                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "\0\4\3\2\\p");
+               set obj.http.Snafu6 =
+                   regsub(obj.http.Foobar, "(b)(a)(r)(f)", "\4\&\3\2p\");
        }
 } -start 
 
@@ -31,12 +33,14 @@ client c1 {
        rxresp
        expect resp.status == 200
        expect resp.http.X-Varnish == "1001"
-       expect resp.http.foobar == "barf"
-       expect resp.http.snafu1 == "bararf"
-       expect resp.http.snafu2 == "frap"
-       expect resp.http.snafu3 == "f$rap"
-       expect resp.http.snafu4 == "f&rap"
-       expect resp.http.snafu5 == "barffra$p"
+       expect resp.http.foobar == "_barf_"
+       expect resp.http.snafu1 == "_bararf_"
+       expect resp.http.snafu2 == "_frap_"
+       expect resp.http.snafu3 == "_f\rap_"
+       expect resp.http.snafu4 == "_f&rap_"
+       expect resp.http.snafu5 == "_barffra\p_"
+       # NB: have to escape the \\ in the next line
+       expect resp.http.snafu6 == "_f&rap\\_"
 }
 
 client c1 -run