Commit d25ce0b5 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Rather than add to a never ending list of things we cannot add/subtract,

examine the list of things we can handle, and if not, and we are
looking for strings anyway, convert to string right away.

Really fixes #2205
parent a7ceb252
...@@ -77,6 +77,7 @@ varnish v1 -vcl { ...@@ -77,6 +77,7 @@ varnish v1 -vcl {
set req.http.foo = now - 1s; set req.http.foo = now - 1s;
set req.http.foo = now - now; set req.http.foo = now - now;
set req.http.foo = 1 + 1s;
set req.http.foo = 1 + 1; set req.http.foo = 1 + 1;
set req.http.foo = 1 - 1; set req.http.foo = 1 - 1;
...@@ -169,13 +170,6 @@ varnish v1 -errvcl {TIME + TIME not possible.} { ...@@ -169,13 +170,6 @@ varnish v1 -errvcl {TIME + TIME not possible.} {
} }
} }
varnish v1 -errvcl {TIME + INT not possible.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.foo = now + 1;
}
}
varnish v1 -errvcl {INT + STRING not possible.} { varnish v1 -errvcl {INT + STRING not possible.} {
backend b { .host = "127.0.0.1"; } backend b { .host = "127.0.0.1"; }
sub vcl_backend_response { sub vcl_backend_response {
...@@ -190,34 +184,6 @@ varnish v1 -errvcl {INT + TIME not possible.} { ...@@ -190,34 +184,6 @@ varnish v1 -errvcl {INT + TIME not possible.} {
} }
} }
varnish v1 -errvcl {INT + DURATION not possible.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.foo = 1 + 1s;
}
}
varnish v1 -errvcl {DURATION + INT not possible.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.foo = 1s + 1;
}
}
varnish v1 -errvcl {DURATION + TIME not possible.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.foo = 1s + now;
}
}
varnish v1 -errvcl {DURATION + STRING not possible.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.foo = 1s + "foo";
}
}
varnish v1 -errvcl {DURATION + INT not possible.} { varnish v1 -errvcl {DURATION + INT not possible.} {
backend b { .host = "127.0.0.1"; } backend b { .host = "127.0.0.1"; }
sub vcl_recv { sub vcl_recv {
......
...@@ -376,10 +376,11 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt) ...@@ -376,10 +376,11 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt)
uint8_t constant = EXPR_VAR; uint8_t constant = EXPR_VAR;
CHECK_OBJ_NOTNULL(*e, EXPR_MAGIC); CHECK_OBJ_NOTNULL(*e, EXPR_MAGIC);
AN(fmt == STRING || fmt == STRING_LIST); assert(fmt == STRING || fmt == STRING_LIST);
AZ(fmt == (*e)->fmt); assert(fmt != (*e)->fmt);
if ((*e)->fmt == STRING || ((*e)->fmt == STRING_LIST && vcc_isconst(*e))) { if ((*e)->fmt == STRING ||
((*e)->fmt == STRING_LIST && vcc_isconst(*e))) {
(*e)->fmt = fmt; (*e)->fmt = fmt;
return; return;
} }
...@@ -1018,17 +1019,6 @@ static const struct adds { ...@@ -1018,17 +1019,6 @@ static const struct adds {
{ '+', INT, REAL, REAL }, { '+', INT, REAL, REAL },
{ '-', INT, REAL, REAL }, { '-', INT, REAL, REAL },
/* Error */
{ '+', DURATION, INT, VOID },
{ '+', DURATION, REAL, VOID },
{ '+', DURATION, TIME, VOID },
{ '+', DURATION, STRING, VOID },
{ '+', INT, DURATION, VOID },
{ '+', IP, IP, VOID },
{ '+', REAL, DURATION, VOID },
{ '+', TIME, INT, VOID },
{ '+', TIME, REAL, VOID },
{ EOI, VOID, VOID, VOID } { EOI, VOID, VOID, VOID }
}; };
...@@ -1044,15 +1034,27 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt) ...@@ -1044,15 +1034,27 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt)
*e = NULL; *e = NULL;
vcc_expr_mul(tl, e, fmt); vcc_expr_mul(tl, e, fmt);
ERRCHK(tl); ERRCHK(tl);
if (tl->t->tok != '+' && tl->t->tok != '-')
return;
f2 = (*e)->fmt; f2 = (*e)->fmt;
for (ap = vcc_adds; ap->op != EOI; ap++)
if (ap->a == f2 && ap->op == tl->t->tok)
break;
if (ap->op == EOI &&
(fmt == STRING || fmt == STRING_LIST) &&
f2 != STRING && f2 != STRING_LIST) {
vcc_expr_tostring(tl, e, fmt);
f2 = (*e)->fmt;
}
while (tl->t->tok == '+' || tl->t->tok == '-') { while (tl->t->tok == '+' || tl->t->tok == '-') {
tk = tl->t; tk = tl->t;
vcc_NextToken(tl); vcc_NextToken(tl);
if (f2 == TIME) if (f2 == TIME)
vcc_expr_mul(tl, &e2, DURATION); vcc_expr_mul(tl, &e2, DURATION);
else if (f2 == IP)
vcc_expr_mul(tl, &e2, STRING);
else else
vcc_expr_mul(tl, &e2, f2); vcc_expr_mul(tl, &e2, f2);
ERRCHK(tl); ERRCHK(tl);
......
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