Commit 642bb86c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add code to replace the five mandatory XML 1.0 entity references.

Inspired by: patch submitted in #607



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4426 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent c88a8e3c
......@@ -152,6 +152,37 @@ CMP(const struct esi_ptr *ep, const char *str)
}
/*--------------------------------------------------------------------
* 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, "&apos;", '\'');
R(6, "&quot;", '"');
R(4, "&lt;", '<');
R(4, "&gt;", '>');
R(5, "&amp;", '&');
}
#undef R
*d++ = *s++;
}
t->e = d;
t->e[0] = '\0';
}
/*--------------------------------------------------------------------
* Report a parsing error
*
......@@ -385,7 +416,7 @@ esi_handle_include(struct esi_work *ew)
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 @@ esi_handle_include(struct esi_work *ew)
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;
......
# $Id$
test "Test XML 1.0 entity references"
server s1 {
rxreq
expect req.url == "/"
txresp -body {
<esi:include src="&amp;"/>
<esi:include src="&lt;"/>
<esi:include src="&gt;"/>
<esi:include src="&apos;"/>
<esi:include src="&quot;"/>
}
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
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