Commit 1c5b96a7 authored by Geoff Simmons's avatar Geoff Simmons

sub() function fails if the pattern is undefined

parent 264ce0df
......@@ -59,6 +59,10 @@ varnish v1 -vcl {
set resp.http.undeffallback = b.sub("b", "x", req.http.undef);
set resp.http.undeffallbackf
= re2.sub("b", "b", "x", req.http.undef);
# Undefined pattern in the function
set resp.http.undefpattern
= re2.sub(req.http.undef, "", "", "pattern undef");
}
} -start
......@@ -93,11 +97,14 @@ client c1 {
expect resp.http.undeffallback == "**SUB METHOD FAILED**"
expect resp.http.undeffallbackf == "**SUB FUNCTION FAILED**"
expect resp.http.undefpattern == "pattern undef"
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: b.sub..: fallback is undefined$"
expect * = VCL_Error "^vmod re2 error: re2.sub..: fallback is undefined$"
expect * = VCL_Error "^vmod re2 error: re2.sub.pattern=<undefined>, fallback=.pattern undef..: pattern is undefined$"
expect * = End
} -run
......@@ -742,8 +742,11 @@ vmod_sub(VRT_CTX, VCL_STRING pattern, VCL_STRING text, VCL_STRING rewrite,
ERR(ctx, "re2.sub(): fallback is undefined");
return "**SUB FUNCTION FAILED**";
}
if (pattern == NULL)
pattern = "";
if (pattern == NULL) {
VERR(ctx, "re2.sub(pattern=<undefined>, fallback=\"%s\"): "
"pattern is undefined", fallback);
return fallback;
}
if (text == NULL)
text = "";
if (rewrite == NULL)
......
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