Commit 957c035e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk/varnish-cache@2741 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent b3c61816
......@@ -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;
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment