Commit c89737b8 authored by Geoff Simmons's avatar Geoff Simmons

sub() method and function fail if the text param is NULL

parent 1c5b96a7
......@@ -63,6 +63,12 @@ varnish v1 -vcl {
# Undefined pattern in the function
set resp.http.undefpattern
= re2.sub(req.http.undef, "", "", "pattern undef");
# Undefined text
set resp.http.undeftext
= b.sub(req.http.undef, "x", "text undef");
set resp.http.undeftextf
= re2.sub("b", req.http.undef, "x", "text undef");
}
} -start
......@@ -99,12 +105,19 @@ client c1 {
expect resp.http.undeffallbackf == "**SUB FUNCTION FAILED**"
expect resp.http.undefpattern == "pattern undef"
expect resp.http.undeftext == "text undef"
expect resp.http.undeftextf == "text 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 * = VCL_Error "^vmod re2 error: b.sub.text=<undefined>, fallback=.text undef..: text is undefined$"
expect * = VCL_Error "^vmod re2 error: re2.sub.pattern=.b., text=<undefined>, fallback=.text undef..: text is undefined$"
expect * = End
} -run
......@@ -430,8 +430,11 @@ vmod_regex_sub(VRT_CTX, struct vmod_re2_regex *re, VCL_STRING text,
VERR(ctx, "%s.sub(): fallback is undefined", re->vcl_name);
return "**SUB METHOD FAILED**";
}
if (text == NULL)
text = "";
if (text == NULL) {
VERR(ctx, "%s.sub(text=<undefined>, fallback=\"%s\"): "
"text is undefined", re->vcl_name, fallback);
return fallback;
}
if (rewrite == NULL)
rewrite = "";
......@@ -747,8 +750,11 @@ vmod_sub(VRT_CTX, VCL_STRING pattern, VCL_STRING text, VCL_STRING rewrite,
"pattern is undefined", fallback);
return fallback;
}
if (text == NULL)
text = "";
if (text == NULL) {
VERR(ctx, "re2.sub(pattern=\"%s\", text=<undefined>, "
"fallback=\"%s\"): text is undefined", pattern, fallback);
return fallback;
}
if (rewrite == NULL)
rewrite = "";
......
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