Commit 0e1c14c2 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r3534: Add "no match" operator !~ to VCL regexps



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@3718 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3b5cb326
# $Id$
test "regexp match and no-match"
server s1 {
rxreq
txresp -hdr "Foo: bar" -hdr "Bar: foo" -body "1111\n"
} -start
varnish v1 -vcl+backend {
sub vcl_fetch {
if (obj.http.foo ~ "bar") {
set obj.http.foo1 = "1";
}
if (obj.http.bar !~ "bar") {
set obj.http.bar1 = "1";
}
}
} -start
client c1 {
txreq
rxresp
expect resp.http.foo1 == "1"
expect resp.http.bar1 == "1"
} -run
......@@ -22,6 +22,7 @@ vcl_fixed_token(const char *p, const char **q)
switch (p[0]) {
case '!':
M2('~', T_NOMATCH);
M2('=', T_NEQ);
M1();
case '%':
......@@ -146,6 +147,7 @@ const char * const vcl_tnames[256] = {
[T_LEQ] = "<=",
[T_MUL] = "*=",
[T_NEQ] = "!=",
[T_NOMATCH] = "!~",
[T_SHL] = "<<",
[T_SHR] = ">>",
[VAR] = "VAR",
......
......@@ -88,6 +88,7 @@ set magic {
{"-=" DECR}
{"*=" MUL}
{"/=" DIV}
{"!~" NOMATCH}
}
# Single char tokens
......
......@@ -248,12 +248,15 @@ Cond_String(const struct var *vp, struct tokenlist *tl)
switch (tl->t->tok) {
case '~':
case T_NOMATCH:
Fb(tl, 1, "%sVRT_re_match(",
tl->t->tok == '~' ? "" : "!");
vcc_NextToken(tl);
ExpectErr(tl, CSTR);
p = vcc_regexp(tl, 0);
ERRCHK(tl);
vcc_NextToken(tl);
Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p);
Fb(tl, 1, "%s, %s)\n", vp->rname, p);
break;
case T_EQ:
case T_NEQ:
......
......@@ -26,9 +26,10 @@
#define T_DECR 144
#define T_MUL 145
#define T_DIV 146
#define ID 147
#define VAR 148
#define CNUM 149
#define CSTR 150
#define EOI 151
#define CSRC 152
#define T_NOMATCH 147
#define ID 148
#define VAR 149
#define CNUM 150
#define CSTR 151
#define EOI 152
#define CSRC 153
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment