[master] 50515b2 Handle integers in boolean expressions

Federico G. Schwindt fgsch at lodoss.net
Wed Sep 14 00:47:09 CEST 2016


commit 50515b2214d38d1eba0331aa0b88e9e6b6687da7
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Tue Sep 13 23:40:04 2016 +0100

    Handle integers in boolean expressions
    
    Zero is false, all other values are true.

diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index cd0ab28..3fd7e69 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -127,6 +127,16 @@ varnish v1 -vcl {
 	}
 }
 
+
+varnish v1 -vcl {
+	import std;
+	backend b { .host = "127.0.0.1"; }
+	sub vcl_recv {
+		if (std.integer("1", 1)) {
+		}
+	}
+}
+
 # XXX: not the most clear error message
 varnish v1 -errvcl {STRING - STRING not possible.} {
 	backend b { .host = "127.0.0.1"; }
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 4ced132..7d594cf 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1200,7 +1200,9 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	default:
 		break;
 	}
-	if (fmt == BOOL && ((*e)->fmt == STRING || (*e)->fmt == BACKEND)) {
+	if (fmt == BOOL &&
+	    ((*e)->fmt == STRING || (*e)->fmt == BACKEND ||
+	     (*e)->fmt == INT)) {
 		*e = vcc_expr_edit(BOOL, "(\v1 != 0)", *e, NULL);
 		return;
 	}



More information about the varnish-commit mailing list