Hi,  I've attached my suggested fix for #900.  As a side effect, it
allows you to embed binary data in arbitrary strings, so you can serve
PNG or GIF images from vcl_error.

Comments very welcome, both on the approach and what we should allow.

Regards,
-- 
Tollef Fog Heen
Varnish Software
t: +47 21 98 92 64
>From 3537e7c802737be7c8b461b0414103f7d15c4954 Mon Sep 17 00:00:00 2001
From: Tollef Fog Heen <[email protected]>
Date: Fri, 15 Apr 2011 10:38:17 +0200
Subject: [PATCH] Fix up \" and \\ support in VCL

Fixes #900
---
 bin/varnishtest/tests/r00900.vtc |   21 +++++++++++++++++++++
 lib/libvcl/vcc_token.c           |   20 +++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletions(-)
 create mode 100644 bin/varnishtest/tests/r00900.vtc

diff --git a/bin/varnishtest/tests/r00900.vtc b/bin/varnishtest/tests/r00900.vtc
new file mode 100644
index 0000000..eb13940
--- /dev/null
+++ b/bin/varnishtest/tests/r00900.vtc
@@ -0,0 +1,21 @@
+
+test "Test backslash escapes in VCL"
+
+server s1 {
+	rxreq 
+	txresp
+} -start
+
+varnish v1 -vcl+backend { 
+	sub vcl_deliver {
+		set resp.http.foo1 = "abcd\\abcd";
+		set resp.http.foo2 = "abcd\"abcd";
+	}
+} -start 
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.foo1 == "abcd\\abcd"
+	expect resp.http.foo2 == "abcd\"abcd"
+} -run
diff --git a/lib/libvcl/vcc_token.c b/lib/libvcl/vcc_token.c
index 56c9672..9625733 100644
--- a/lib/libvcl/vcc_token.c
+++ b/lib/libvcl/vcc_token.c
@@ -351,13 +351,26 @@ vcc_decstr(struct vcc *tl)
 {
 	char *q;
 	unsigned int l;
+	unsigned int i, o;
 
 	assert(tl->t->tok == CSTR);
 	l = (tl->t->e - tl->t->b) - 2;
 	tl->t->dec = TlAlloc(tl, l + 1);
 	assert(tl->t->dec != NULL);
 	q = tl->t->dec;
-	memcpy(q, tl->t->b + 1, l);
+	i = 1;
+	o = 0;
+	while (i <= l) {
+		if (tl->t->b[i] == '\\') {
+			i += BackSlash(&tl->t->b[i], &q[o]);
+			o++;
+			continue;
+		}
+		q[o] = tl->t->b[i];
+		i++;
+		o++;
+	}
+	printf("%s\n", q);
 	q[l] = '\0';
 	return (0);
 }
@@ -498,6 +511,11 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
 		/* Match strings, with \\ and \" escapes */
 		if (*p == '"') {
 			for (q = p + 1; q < sp->e; q++) {
+				if (q+1 < sp->e && q[0] == '\\' &&
+				    (q[1] == '\\' || q[1] == '"')) {
+					q += 2;
+					continue;
+				}
 				if (*q == '"') {
 					q++;
 					break;
-- 
1.7.4.1

_______________________________________________
varnish-dev mailing list
[email protected]
http://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to