Commit c71e7938 authored by Geoff Simmons's avatar Geoff Simmons

Add the element enum to .sub().

parent 1f071898
......@@ -869,8 +869,8 @@ Example::
.. _xset.sub():
STRING xset.sub(STRING str, STRING sub, BOOL all, INT n, ENUM select)
---------------------------------------------------------------------
STRING xset.sub(STRING str, STRING sub, BOOL all, INT n, STRING element, ENUM select)
-------------------------------------------------------------------------------------
::
......@@ -879,6 +879,7 @@ STRING xset.sub(STRING str, STRING sub, BOOL all, INT n, ENUM select)
STRING sub,
BOOL all=0,
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
......
......@@ -50,6 +50,13 @@ varnish v1 -vcl {
set resp.http.N-4-F = s.sub("/", client.ip, false, 4);
set resp.http.N-5-F = s.sub(client.ip, client.ip, false, 5);
set resp.http.Foo = s.sub("_barf_", "\0\0", element="foo");
set resp.http.Bar = s.sub("_barf_", "\4\3\2p", element="bar");
set resp.http.Baz = s.sub(resp.http.baz, "XXX", element="baz");
set resp.http.Quux = s.sub("/", client.ip, element="quux");
set resp.http.Foobar
= s.sub(client.ip, client.ip, element="foobar");
return (deliver);
}
} -start
......@@ -79,6 +86,12 @@ client c1 {
expect resp.http.N-3-F == resp.http.N-3
expect resp.http.N-4-F == resp.http.N-4
expect resp.http.N-5-F == resp.http.N-5
expect resp.http.Foo == resp.http.N-1-1
expect resp.http.Bar == resp.http.N-2-1
expect resp.http.Baz == resp.http.N-3
expect resp.http.Quux == resp.http.N-4
expect resp.http.Foobar == resp.http.N-5
} -run
# cf. Varnish c00047.vtc, r01557.vtc, r01566.vtc
......@@ -156,6 +169,10 @@ varnish v1 -vcl {
if (req.http.Suball) {
set resp.http.Suball = s.sub("foo", "bar", true);
}
if (req.http.Element) {
set resp.http.Element = s.sub("foo", "bar",
element=req.http.Element);
}
return (deliver);
}
}
......@@ -175,6 +192,11 @@ logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect * = VCL_Error {^vmod selector failure: s\.sub\(\) called without prior match$}
expect * = VCL_return fail
expect * = End
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.sub\(element="oof"\): no such element$}
expect * = VCL_return fail
expect * = End
} -start
client c1 {
......@@ -192,6 +214,11 @@ client c1 {
expect_close
} -run
client c1 {
txreq -hdr "Element: oof"
expect_close
} -run
logexpect l1 -wait
# Examples from the docs
......
......@@ -847,11 +847,12 @@ vmod_set_re_match(VRT_CTX, struct vmod_selector_set *set, VCL_STRING subject,
VCL_STRING
vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
VCL_STRING sub, VCL_BOOL all, VCL_INT n, VCL_ENUM selects)
VCL_STRING sub, VCL_BOOL all, VCL_INT n, VCL_STRING element,
VCL_ENUM selects)
{
vre_t *re;
re = get_re(ctx, set, n, NULL, selects, "sub");
re = get_re(ctx, set, n, element, selects, "sub");
if (re == NULL)
return (NULL);
return (VRT_regsub(ctx, all, str, re, sub));
......
......@@ -766,6 +766,7 @@ Example::
}
$Method STRING .sub(STRING str, STRING sub, BOOL all=0, INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
......
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