/* Check regexp stuff */
if (re_map->map_flags & RSPAMD_REGEXP_MAP_FLAG_GLOB) {
- char *anchored;
-
- escaped = rspamd_str_regexp_escape(key, strlen(key), &escaped_len,
- RSPAMD_REGEXP_ESCAPE_GLOB | RSPAMD_REGEXP_ESCAPE_UTF);
/* Glob semantics: the pattern must match the subject as a whole */
- anchored = g_strdup_printf("^(?:%s)$", escaped);
- re = rspamd_regexp_new(anchored, NULL, &err);
- g_free(anchored);
+ escaped = rspamd_str_regexp_escape(key, strlen(key), &escaped_len,
+ RSPAMD_REGEXP_ESCAPE_GLOB | RSPAMD_REGEXP_ESCAPE_UTF |
+ RSPAMD_REGEXP_ESCAPE_ANCHOR);
+ re = rspamd_regexp_new(escaped, NULL, &err);
g_free(escaped);
}
else {
}
}
+ if (flags & RSPAMD_REGEXP_ESCAPE_ANCHOR) {
+ /* Room for ^(?: and )$ */
+ len += 6;
+ }
+
if (flags & RSPAMD_REGEXP_ESCAPE_UTF) {
if (rspamd_fast_utf8_validate(pattern, slen) != 0) {
tmp_utf = rspamd_str_make_utf_valid(pattern, slen, NULL, NULL);
d = res;
dend = d + len;
+ if (flags & RSPAMD_REGEXP_ESCAPE_ANCHOR) {
+ memcpy(d, "^(?:", 4);
+ d += 4;
+ }
+
while (p < end) {
g_assert(d < dend);
t = *p++;
*d++ = t;
}
+ if (flags & RSPAMD_REGEXP_ESCAPE_ANCHOR) {
+ *d++ = ')';
+ *d++ = '$';
+ }
+
*d = '\0';
if (dst_len) {
RSPAMD_REGEXP_ESCAPE_UTF = 1u << 0,
RSPAMD_REGEXP_ESCAPE_GLOB = 1u << 1,
RSPAMD_REGEXP_ESCAPE_RE = 1u << 2,
+ /* Wrap the result into ^(?:...)$ so it matches the subject as a whole */
+ RSPAMD_REGEXP_ESCAPE_ANCHOR = 1u << 3,
};
/**