r2741 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at projects.linpro.no phk at projects.linpro.no
Fri Jun 20 13:58:26 CEST 2008


Author: phk
Date: 2008-06-20 13:58:25 +0200 (Fri, 20 Jun 2008)
New Revision: 2741

Modified:
   trunk/varnish-cache/bin/varnishd/cache_vrt_re.c
   trunk/varnish-cache/bin/varnishtest/tests/c00001.vtc
Log:
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_"




Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt_re.c	2008-06-20 10:20:30 UTC (rev 2740)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt_re.c	2008-06-20 11:58:25 UTC (rev 2741)
@@ -131,20 +131,17 @@
 		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;

Modified: trunk/varnish-cache/bin/varnishtest/tests/c00001.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00001.vtc	2008-06-20 10:20:30 UTC (rev 2740)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00001.vtc	2008-06-20 11:58:25 UTC (rev 2741)
@@ -5,22 +5,24 @@
 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 @@
 	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




More information about the varnish-commit mailing list