[master] df243af68 Allow non-literal negative VCL expressions

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Nov 13 09:08:06 UTC 2019


commit df243af68312df8869cd00d2826817a4deeffebc
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Nov 12 19:13:50 2019 +0100

    Allow non-literal negative VCL expressions

diff --git a/bin/varnishtest/tests/v00019.vtc b/bin/varnishtest/tests/v00019.vtc
index d81455a15..e37751869 100644
--- a/bin/varnishtest/tests/v00019.vtc
+++ b/bin/varnishtest/tests/v00019.vtc
@@ -70,3 +70,10 @@ varnish v1 -errvcl {Symbol not found: 'req.http.req.http.foo'} {
 		set req.http.req.http.foo = "bar";
 	}
 }
+
+varnish v1 -errvcl {Unknown token '--' when looking for INT} {
+	backend be none;
+	sub vcl_synth {
+		set resp.status = --200;
+	}
+}
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 919624a41..238927c34 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -327,6 +327,7 @@ varnish v1 -vcl+backend {
 }
 
 varnish v1 -vcl+backend {
+	import std;
 	import debug;
 	sub vcl_deliver {
 		// Ticket 2745
@@ -339,6 +340,9 @@ varnish v1 -vcl+backend {
 	sub vcl_deliver {
 		set resp.http.p = (0 + 9223372036854775807);
 		set resp.http.n = (0 - 9223372036854775807);
+		if (resp.status == -(-200)) {
+			set resp.http.o = -std.integer("-200");
+		}
 	}
 } -start
 
@@ -350,4 +354,32 @@ client c1 {
 	expect resp.http.bar == "false"
 	expect resp.http.p == 9223372036854775807
 	expect resp.http.n == -9223372036854775807
+	expect resp.http.o == 200
+} -run
+
+varnish v1 -vcl {
+	import std;
+	backend be none;
+	sub vcl_recv {
+		return (synth(200));
+	}
+	sub vcl_synth {
+		if (req.url ~ "double-minus") {
+			set resp.status = -(-204);
+		}
+		if (req.url ~ "minus-std") {
+			set resp.status = -std.integer("-204");
+		}
+		return (deliver);
+	}
+}
+
+client c1 {
+	txreq -url "/double-minus"
+	rxresp
+	expect resp.status == 204
+
+	txreq -url "/minus-std"
+	rxresp
+	expect resp.status == 204
 } -run
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index d7c32a8dc..bab9251b5 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -764,8 +764,12 @@ vcc_expr5(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 		    fmt != STRINGS)
 			break;
 		vcc_NextToken(tl);
-		if (tl->t->tok != FNUM && tl->t->tok != CNUM)
-			break;
+		if (tl->t->tok != FNUM && tl->t->tok != CNUM) {
+			vcc_expr_cor(tl, &e1, fmt);
+			ERRCHK(tl);
+			*e = vcc_expr_edit(tl, e1->fmt, "-(\v1)", e1, NULL);
+			return;
+		}
 		sign = "-";
 		/* FALLTHROUGH */
 	case FNUM:


More information about the varnish-commit mailing list