Commit 264ce0df authored by Geoff Simmons's avatar Geoff Simmons

sub() method and function fail if the fallback is NULL

parent f3579552
......@@ -54,6 +54,11 @@ varnish v1 -vcl {
# Match failure
set resp.http.bfail = b.sub("acd", "x", "fallbackb");
set resp.http.bfailf = re2.sub("b", "acd", "x", "fallbackf");
# Undefined fallback
set resp.http.undeffallback = b.sub("b", "x", req.http.undef);
set resp.http.undeffallbackf
= re2.sub("b", "b", "x", req.http.undef);
}
} -start
......@@ -85,4 +90,14 @@ client c1 {
expect resp.http.bfail == "fallbackb"
expect resp.http.bfailf == "fallbackf"
expect resp.http.undeffallback == "**SUB METHOD FAILED**"
expect resp.http.undeffallbackf == "**SUB FUNCTION FAILED**"
} -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 * = End
} -run
......@@ -426,12 +426,14 @@ vmod_regex_sub(VRT_CTX, struct vmod_re2_regex *re, VCL_STRING text,
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(re, VMOD_RE2_REGEX_MAGIC);
if (fallback == NULL) {
VERR(ctx, "%s.sub(): fallback is undefined", re->vcl_name);
return "**SUB METHOD FAILED**";
}
if (text == NULL)
text = "";
if (rewrite == NULL)
rewrite = "";
if (fallback == NULL)
fallback = "";
return sub(ctx, re->vre2, text, rewrite, fallback);
}
......@@ -736,14 +738,16 @@ vmod_sub(VRT_CTX, VCL_STRING pattern, VCL_STRING text, VCL_STRING rewrite,
const char *ret, *err;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (fallback == NULL) {
ERR(ctx, "re2.sub(): fallback is undefined");
return "**SUB FUNCTION FAILED**";
}
if (pattern == NULL)
pattern = "";
if (text == NULL)
text = "";
if (rewrite == NULL)
rewrite = "";
if (fallback == NULL)
fallback = "";
if ((err = vre2_init(&vre2, pattern, utf8, posix_syntax, longest_match,
max_mem, literal, never_nl, dot_nl, never_capture,
......
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