[master] c936b7a Allow to use regex matches in expressions

Federico G. Schwindt fgsch at lodoss.net
Thu Sep 8 10:30:30 CEST 2016


commit c936b7a446e94d4634c01199f61e1c00149b168a
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Thu Sep 8 01:16:37 2016 +0100

    Allow to use regex matches in expressions
    
    E.g. set req.http.foo = req.http.bar ~ "foobar"
    
    Related to #2075.

diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index e041356..b800411 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -115,6 +115,11 @@ varnish v1 -vcl {
 		set req.http.foo = 3.6 * 1.4;
 		set req.http.foo = 3.6 / 1.4;
 
+		set req.http.foo = req.http.foo ~ "bar";
+		set req.http.foo = req.http.foo !~ "bar";
+		set req.http.foo = "foo" ~ "bar";
+		set req.http.foo = "foo" !~ "bar";
+
 		set req.ttl = 1s;
 	}
 }
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index d91c8bd..6259934 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1136,7 +1136,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 		*e = vcc_expr_edit(BOOL, cp->emit, *e, e2);
 		return;
 	}
-	if ((*e)->fmt == STRING &&
+	if (((*e)->fmt == STRING || (*e)->fmt == STRING_LIST) &&
 	    (tl->t->tok == '~' || tl->t->tok == T_NOMATCH)) {
 		not = tl->t->tok == '~' ? "" : "!";
 		vcc_NextToken(tl);



More information about the varnish-commit mailing list