[master] cc513fd Fix a VCL expression type error: TIME +/- DURATION should return TIME

Poul-Henning Kamp phk at varnish-cache.org
Thu Oct 11 13:08:10 CEST 2012


commit cc513fdc6cc098fcdc378af6ec80959a5c744054
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 11 11:07:25 2012 +0000

    Fix a VCL expression type error:  TIME +/- DURATION should return TIME
    
    Fixes	#1211
    
    Thanks to:	Federico G. Schwindt

diff --git a/bin/varnishtest/tests/r01211.vtc b/bin/varnishtest/tests/r01211.vtc
new file mode 100644
index 0000000..83914b7
--- /dev/null
+++ b/bin/varnishtest/tests/r01211.vtc
@@ -0,0 +1,22 @@
+varnishtest "TIME +/- DURATION -> TIME"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+
+	sub vcl_deliver {
+		set resp.http.bar = now + 4 d;
+		set resp.http.foo = now - 4 d;
+	}
+
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.bar ~ "..., .. ... 20[1-9][0-9] ..:..:.. GMT"
+	expect resp.http.foo ~ "..., .. ... 20[1-9][0-9] ..:..:.. GMT"
+} -run
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index 72c26a9..06f93ec 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -847,6 +847,9 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
 		ERRCHK(tl);
 		if (tk->tok == '-' && (*e)->fmt == TIME && e2->fmt == TIME) {
 			/* OK */
+		} else if ((*e)->fmt == TIME && e2->fmt == DURATION) {
+			f2 = TIME;
+			/* OK */
 		} else if (tk->tok == '-' &&
 		    (*e)->fmt == BYTES && e2->fmt == BYTES) {
 			/* OK */



More information about the varnish-commit mailing list