From 384c538df5d14787e406b0bef15d4d3438d1e8c8 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 20 Jun 2008 11:58:25 +0000 Subject: [PATCH] NB: FLAGDAY! 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 | 19 ++++++------- .../bin/varnishtest/tests/c00001.vtc | 28 +++++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_vrt_re.c b/varnish-cache/bin/varnishd/cache_vrt_re.c index 88420326..08de0b44 100644 --- a/varnish-cache/bin/varnishd/cache_vrt_re.c +++ b/varnish-cache/bin/varnishd/cache_vrt_re.c @@ -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; diff --git a/varnish-cache/bin/varnishtest/tests/c00001.vtc b/varnish-cache/bin/varnishtest/tests/c00001.vtc index fa634a9a..3db9bdfb 100644 --- a/varnish-cache/bin/varnishtest/tests/c00001.vtc +++ b/varnish-cache/bin/varnishtest/tests/c00001.vtc @@ -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 -- 2.39.5