[master] b77b70951 vcc_expr: Allow STRING <cmp> STRANDS comparison

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Jul 9 16:49:06 UTC 2024


commit b77b709510f1e1ff4792ac9bc9c3836d1a5249ec
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Jul 9 11:01:40 2024 +0200

    vcc_expr: Allow STRING <cmp> STRANDS comparison
    
    This otherwise fails on a technicality that suggests the original intent
    was to allow such a comparison:
    
        Comparison of different types: STRING '==' STRING
    
    It also fixes the STRANDS <cmp> STRING comparison that failed with a
    different error message.

diff --git a/bin/varnishtest/tests/v00019.vtc b/bin/varnishtest/tests/v00019.vtc
index 24a23b51f..d7604419a 100644
--- a/bin/varnishtest/tests/v00019.vtc
+++ b/bin/varnishtest/tests/v00019.vtc
@@ -69,6 +69,46 @@ varnish v1 -errvcl {Comparison of different types: STRING '==' INT} {
 	}
 }
 
+varnish v1 -vcl {
+	import debug;
+	backend be none;
+	sub vcl_recv {
+		if ("string" == "string") {
+			return (fail("should compile"));
+		}
+	}
+}
+
+varnish v1 -vcl {
+	import debug;
+	backend be none;
+	sub vcl_recv {
+		if ("string" == debug.return_strands("string")) {
+			return (fail("should compile"));
+		}
+	}
+}
+
+varnish v1 -vcl {
+	import debug;
+	backend be none;
+	sub vcl_recv {
+		if (debug.return_strands("string") == "string") {
+			return (fail("should compile"));
+		}
+	}
+}
+
+varnish v1 -vcl {
+	import debug;
+	backend be none;
+	sub vcl_recv {
+		if (debug.return_strands("string") == debug.return_strands("string")) {
+			return (fail("should compile"));
+		}
+	}
+}
+
 varnish v1 -errvcl {Symbol not found: 'req.http.req.http.foo'} {
 	backend b { .host = "${localhost}"; }
 	sub vcl_recv {
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index a0107474a..d1bb53ee6 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1046,6 +1046,11 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	vcc_expr_mul(tl, e, fmt);
 	ERRCHK(tl);
 
+	if (tl->t->tok != '+' && (*e)->fmt->stringform) {
+		vcc_expr_tostring(tl, e);
+		ERRCHK(tl);
+	}
+
 	while (tl->t->tok == '+' || tl->t->tok == '-') {
 		tk = tl->t;
 		for (ap = vcc_adds; ap->op != EOI; ap++)


More information about the varnish-commit mailing list