Commit 6f587a30 authored by Andrew Wiik's avatar Andrew Wiik Committed by Dridi Boukelmoune

Add """ ... """ as a long string format in VCL

parent 7a12b1c3
......@@ -18,6 +18,11 @@ varnish v1 -errvcl {Unterminated long-string, starting at} {
{" }
}
varnish v1 -errvcl {Unterminated long-string, starting at} {
backend b { .host = "127.0.0.1"; }
""" ""
}
varnish v1 -errvcl {Unterminated string at} {
backend b { .host = "127.0.0.1"; }
"
......
varnishtest "long string coverage"
varnish v1 -vcl {
backend default none;
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.body = """{"key":"value"}""";
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.bodylen == 15
expect resp.body == {{"key":"value"}}
} -run
......@@ -462,7 +462,7 @@ vcc_Lexer(struct vcc *tl, const struct source *sp, int eoi)
return;
}
/* Recognize long-strings */
/* Recognize long-strings {" "} */
if (*p == '{' && p[1] == '"') {
for (q = p + 2; q < sp->e; q++) {
if (*q == '"' && q[1] == '}') {
......@@ -487,6 +487,31 @@ vcc_Lexer(struct vcc *tl, const struct source *sp, int eoi)
return;
}
/* Recognize long-strings """ """ */
if (*p == '"' && p[1] == '"' && p[2] == '"') {
for (q = p + 3; q < sp->e; q++) {
if (*q == '"' && q[1] == '"' && q[2] == '"') {
vcc_addtoken(tl, CSTR, sp, p, q + 3);
break;
}
}
if (q < sp->e) {
p = q + 3;
u = tl->t->e - tl->t->b;
u -= 6; /* """ ... """ */
tl->t->dec = TlAlloc(tl, u + 1 );
AN(tl->t->dec);
memcpy(tl->t->dec, tl->t->b + 3, u);
tl->t->dec[u] = '\0';
continue;
}
vcc_addtoken(tl, EOI, sp, p, p + 3);
VSB_cat(tl->sb,
"Unterminated long-string, starting at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
/* Recognize BLOB (= SF-binary) */
if (*p == ':') {
vsb = VSB_new_auto();
......
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