r4426 - in trunk/varnish-cache/bin: varnishd varnishtest/tests
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jan 6 18:06:57 CET 2010
Author: phk
Date: 2010-01-06 18:06:56 +0100 (Wed, 06 Jan 2010)
New Revision: 4426
Added:
trunk/varnish-cache/bin/varnishtest/tests/e00018.vtc
Modified:
trunk/varnish-cache/bin/varnishd/cache_esi.c
Log:
Add code to replace the five mandatory XML 1.0 entity references.
Inspired by: patch submitted in #607
Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-01-06 16:49:53 UTC (rev 4425)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-01-06 17:06:56 UTC (rev 4426)
@@ -153,6 +153,37 @@
/*--------------------------------------------------------------------
+ * Replace the mandatory XML 1.0 entity references, in place.
+ */
+
+static void
+XMLentity(txt *t)
+{
+ char *s, *d;
+
+ for (s = d = t->b; s < t->e; ) {
+ if (*s == '&') {
+#define R(l,f,r) \
+ if (s + l <= t->e && !memcmp(s, f, l)) { \
+ *d++ = r; \
+ s += l; \
+ continue; \
+ }
+ R(6, "'", '\'');
+ R(6, """, '"');
+ R(4, "<", '<');
+ R(4, ">", '>');
+ R(5, "&", '&');
+ }
+#undef R
+ *d++ = *s++;
+ }
+ t->e = d;
+ t->e[0] = '\0';
+}
+
+
+/*--------------------------------------------------------------------
* Report a parsing error
*
* XXX: The "at xxx" count is usually the tail of the sequence. Since we
@@ -385,7 +416,7 @@
WS_Assert(ws);
s = 0;
- if ( val.b != val.e ) {
+ if (val.b != val.e) {
s = Tlen(val) + 1;
c = WS_Alloc(ew->sp->wrk->ws, s);
XXXAN(c);
@@ -395,6 +426,9 @@
val.e[-1] = '\0';
}
+ if (strchr(val.b, '&'))
+ XMLentity(&val);
+
if (Tlen(val) > 7 && !memcmp(val.b, "http://", 7)) {
/* Rewrite to Host: header inplace */
eb->host.b = val.b;
Added: trunk/varnish-cache/bin/varnishtest/tests/e00018.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/e00018.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/e00018.vtc 2010-01-06 17:06:56 UTC (rev 4426)
@@ -0,0 +1,51 @@
+# $Id$
+
+test "Test XML 1.0 entity references"
+
+server s1 {
+ rxreq
+ expect req.url == "/"
+ txresp -body {
+ <esi:include src="&"/>
+ <esi:include src="<"/>
+ <esi:include src=">"/>
+ <esi:include src="'"/>
+ <esi:include src="""/>
+ }
+
+ rxreq
+ expect req.url == "/&"
+ txresp -body "1"
+
+ rxreq
+ expect req.url == "/<"
+ txresp -body "22"
+
+ rxreq
+ expect req.url == "/>"
+ txresp -body "333"
+
+ rxreq
+ expect req.url == {/'}
+ txresp -body "4444"
+
+ rxreq
+ expect req.url == {/"}
+ txresp -body "55555"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_recv {
+ return (pass);
+ }
+ sub vcl_fetch {
+ esi;
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 32
+} -run
More information about the varnish-commit
mailing list