rspamd_regexp_generate_id (pattern, flags, res->id);
/* Check number of captures */
- if (pcre_fullinfo (res->re, res->extra, PCRE_INFO_CAPTURECOUNT,
+ if (pcre_fullinfo (res->raw_re, res->extra, PCRE_INFO_CAPTURECOUNT,
&ncaptures) == 0) {
res->ncaptures = ncaptures;
}
g_assert (g_array_get_element_size (captures) ==
sizeof (struct rspamd_re_capture));
- g_array_set_size (captures, rc - 1);
+ g_array_set_size (captures, rc);
- for (i = 0; i < rc - 1; i ++) {
+ for (i = 0; i < rc; i ++) {
elt = &g_array_index (captures, struct rspamd_re_capture, i);
elt->p = mt + ovec[i * 2];
elt->len = (mt + ovec[i * 2 + 1]) - elt->p;
if (capture) {
lua_newtable (L);
- lua_pushlstring (L, start, end - start);
- lua_rawseti (L, -2, 1);
for (capn = 0; capn < captures->len; capn ++) {
cap = &g_array_index (captures, struct rspamd_re_capture,
capn);
lua_pushlstring (L, cap->p, cap->len);
- lua_rawseti (L, -2, capn + 2);
+ lua_rawseti (L, -2, capn + 1);
}
lua_rawseti (L, -2, ++i);
test("Regexp capture", function()
local cases = {
{'Body=(\\S+)(?: Fuz1=(\\S+))?(?: Fuz2=(\\S+))?',
- 'mc-filter4 1120; Body=1 Fuz1=1 Fuz2=1',
- {'Body=1 Fuz1=1 Fuz2=1', '1', '1', '1'}}
+ 'mc-filter4 1120; Body=1 Fuz1=2 Fuz2=3',
+ {'Body=1 Fuz1=2 Fuz2=3', '1', '2', '3'}},
+ {'Body=(\\S+)(?: Fuz1=(\\S+))?(?: Fuz2=(\\S+))?',
+ 'mc-filter4 1120; Body=1 Fuz1=2', {'Body=1 Fuz1=2', '1', '2'}},
+ {'Body=(\\S+)(?: Fuz1=(\\S+))?(?: Fuz2=(\\S+))?',
+ 'mc-filter4 1120; Body=1 Fuz1=2 mc-filter4 1120; Body=1 Fuz1=2 Fuz2=3',
+ {'Body=1 Fuz1=2', '1', '2'}, {'Body=1 Fuz1=2 Fuz2=3', '1', '2', '3'}},
}
for _,c in ipairs(cases) do
local r = re.create_cached(c[1])
assert_not_nil(res, "cannot find pattern")
- for n,m in ipairs(res[1]) do
- assert_equal(m, c[3][n], string.format("'%s' doesn't match with '%s'",
- c[3][n], c[1]))
+ for k = 3, table.maxn(c) do
+ for n,m in ipairs(c[k]) do
+ assert_equal(res[k - 2][n], c[k][n], string.format("'%s' doesn't match with '%s'",
+ c[k][n], res[k - 2][n]))
+ end
end
end
end)