Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-re2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-re2
Commits
098dda78
Commit
098dda78
authored
Nov 10, 2017
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error handling in set.string(), .backend() and .sub()
Ensure that the retrieved object was saved via set.add().
parent
cc9c0494
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
17 deletions
+127
-17
set.c
src/set.c
+20
-2
set_retrieve.vtc
src/tests/set_retrieve.vtc
+65
-0
set_sub.vtc
src/tests/set_sub.vtc
+42
-15
No files found.
src/set.c
View file @
098dda78
...
...
@@ -76,6 +76,8 @@ struct task_set_match {
size_t
nmatches
;
};
static
const
char
null
[]
=
"NULL"
;
static
inline
int
decimal_digits
(
int
n
)
{
...
...
@@ -510,8 +512,10 @@ vmod_set_sub(VRT_CTX, struct vmod_re2_set *set, VCL_STRING text,
if
(
idx
<
0
)
return
NULL
;
if
(
!
vbit_test
(
set
->
added
[
RE_ADDED
],
idx
))
{
VERR
(
ctx
,
"%s.sub(%s, %s, %lld): Pattern %lld was not added"
,
set
->
vcl_name
,
text
,
rewrite
,
n
,
idx
);
if
(
selects
==
NULL
)
selects
=
null
;
VERR
(
ctx
,
"%s.sub(%s, %s, %lld, %s): Pattern %d was not saved"
,
set
->
vcl_name
,
text
,
rewrite
,
n
,
selects
,
idx
+
1
);
return
NULL
;
}
return
vmod_regex_sub
(
ctx
,
set
->
regex
[
idx
],
text
,
rewrite
,
fallback
);
...
...
@@ -533,6 +537,13 @@ vmod_set_string(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
idx
=
get_match_idx
(
ctx
,
set
,
n
,
selects
,
"string"
);
if
(
idx
<
0
)
return
NULL
;
if
(
!
vbit_test
(
set
->
added
[
STR_ADDED
],
idx
))
{
if
(
selects
==
NULL
)
selects
=
null
;
VERR
(
ctx
,
"%s.string(%lld, %s): String %lld was not added"
,
set
->
vcl_name
,
n
,
selects
,
idx
+
1
);
return
NULL
;
}
return
set
->
string
[
idx
];
}
...
...
@@ -552,5 +563,12 @@ vmod_set_backend(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, VCL_ENUM selects)
idx
=
get_match_idx
(
ctx
,
set
,
n
,
selects
,
"backend"
);
if
(
idx
<
0
)
return
NULL
;
if
(
!
vbit_test
(
set
->
added
[
BE_ADDED
],
idx
))
{
if
(
selects
==
NULL
)
selects
=
null
;
VERR
(
ctx
,
"%s.backend(%lld, %s): Backend %lld was not added"
,
set
->
vcl_name
,
n
,
selects
,
idx
+
1
);
return
NULL
;
}
return
set
->
backend
[
idx
];
}
src/tests/set_retrieve.vtc
View file @
098dda78
...
...
@@ -211,3 +211,68 @@ client c1 {
} -run
logexpect l1 -wait
varnish v1 -vcl {
import ${vmod_re2};
backend be { .host = "${bad_ip}"; }
sub vcl_init {
new s = re2.set();
s.add("foo");
s.add("bar", "baz");
s.compile();
new b = re2.set();
b.add("foo", backend=be);
b.add("bar");
b.compile();
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.s-str-1 = s.string(1);
set resp.http.s-str-2 = s.string(2);
set resp.http.s-match = s.match("foobar");
set resp.http.s-first = s.string(select=FIRST);
set resp.http.s-last = s.string(select=LAST);
set resp.http.b-backend-1 = b.backend(1);
set resp.http.b-backend-2 = b.backend(2);
set resp.http.b-match = b.match("foobar");
set resp.http.b-first = b.backend(select=FIRST);
set resp.http.b-last = b.backend(select=LAST);
}
}
logexpect l1 -v v1 -d 0 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: s.string.1, NULL.: String 1 was not added$"
expect * = VCL_Error "^vmod re2 error: s.string.0, FIRST.: String 1 was not added$"
expect * = VCL_Error "^vmod re2 error: b.backend.2, NULL.: Backend 2 was not added$"
expect * = VCL_Error "^vmod re2 error: b.backend.0, LAST.: Backend 2 was not added$"
expect * = End
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.s-str-1 == ""
expect resp.http.s-str-2 == "baz"
expect resp.http.s-match == "true"
expect resp.http.s-first == resp.http.s-str-1
expect resp.http.s-last == resp.http.s-str-2
expect resp.http.b-backend-1 == "be"
expect resp.http.b-backend-2 == ""
expect resp.http.b-match == "true"
expect resp.http.b-first == resp.http.b-backend-1
expect resp.http.b-last == resp.http.b-backend-2
} -run
logexpect l1 -wait
src/tests/set_sub.vtc
View file @
098dda78
...
...
@@ -12,6 +12,11 @@ varnish v1 -vcl {
s.add("\w+", save=true);
s.add("b", save=true);
s.compile();
new n = re2.set();
n.add("b");
n.add("b+", save=true);
n.compile();
}
sub vcl_recv {
...
...
@@ -19,19 +24,26 @@ varnish v1 -vcl {
}
sub vcl_synth {
set resp.http.sub-1
set resp.http.s
-s
ub-1
= s.sub("the quick brown fox jumps over the lazy dogs.",
"\2\1ay", n=1);
set resp.http.sub-2 = s.sub("abcd.efghi@google.com",
"\0-NOSPAM", n=2);
set resp.http.sub-3 = s.sub("ababababab", "bb", n=3);
set resp.http.match
set resp.http.s
-s
ub-2 = s.sub("abcd.efghi@google.com",
"\0-NOSPAM", n=2);
set resp.http.s
-s
ub-3 = s.sub("ababababab", "bb", n=3);
set resp.http.
s-
match
= s.match("the quick brown fox jumps over the lazy dogs.");
set resp.http.n = s.nmatches();
set resp.http.pangram
set resp.http.
s-
n = s.nmatches();
set resp.http.
s-
pangram
= s.sub("the quick brown fox jumps over the lazy dogs.",
"\2\1ay", select=FIRST);
set resp.http.ab = s.sub("ababababab", "bb", select=LAST);
set resp.http.s-ab = s.sub("ababababab", "bb", select=LAST);
set resp.http.n-sub-1 = n.sub("bbbbbb", "bb", n=1);
set resp.http.n-sub-2 = n.sub("bbbbbb", "bb", n=2);
set resp.http.n-match = n.match("bbbbbb");
set resp.http.n-n = n.nmatches();
set resp.http.n-first = n.sub("bbbbbb", "bb", select=FIRST);
set resp.http.n-last = n.sub("bbbbbb", "bb", select=LAST);
}
} -start
...
...
@@ -39,11 +51,26 @@ client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.sub-1 == "ethay quick brown fox jumps over the lazy dogs."
expect resp.http.sub-2 == "abcd-NOSPAM.efghi@google.com"
expect resp.http.sub-3 == "abbabababab"
expect resp.http.match == "true"
expect resp.http.n == "3"
expect resp.http.pangram == resp.http.sub-1
expect resp.http.ab == resp.http.sub-3
expect resp.http.s-sub-1 == "ethay quick brown fox jumps over the lazy dogs."
expect resp.http.s-sub-2 == "abcd-NOSPAM.efghi@google.com"
expect resp.http.s-sub-3 == "abbabababab"
expect resp.http.s-match == "true"
expect resp.http.s-n == "3"
expect resp.http.s-pangram == resp.http.s-sub-1
expect resp.http.s-ab == resp.http.s-sub-3
expect resp.http.n-sub-1 == ""
expect resp.http.n-sub-2 == "bb"
expect resp.http.n-match == "true"
expect resp.http.n-n == "2"
expect resp.http.n-first == resp.http.n-sub-1
expect resp.http.n-last == resp.http.n-sub-2
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error "^vmod re2 error: n.sub.bbbbbb, bb, 1, NULL.: Pattern 1 was not saved$"
expect * = VCL_Error "^vmod re2 error: n.sub.bbbbbb, bb, 0, FIRST.: Pattern 1 was not saved$"
expect * = End
} -run
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment