commit 228c834: [Minor] Glob patterns actually allow ranges
Vsevolod Stakhov
vsevolod at rspamd.com
Sat Jul 30 19:56:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-07-30 20:43:23 +0100
URL: https://github.com/rspamd/rspamd/commit/228c83425d80b79657b7c151c8656d048857330c
[Minor] Glob patterns actually allow ranges
---
src/libutil/str_util.c | 37 ++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 849d11a4f..86369909a 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -3203,7 +3203,6 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen,
switch (t) {
case '[':
case ']':
- case '-':
case '\\':
case '{':
case '}':
@@ -3219,6 +3218,36 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen,
*d++ = '\\';
}
break;
+ case '-':
+ if (flags & RSPAMD_REGEXP_ESCAPE_GLOB) {
+ /*
+ * For glob patterns, we need to ensure that a previous character is alphanumeric
+ * and there is `[` symbol somewhere before
+ */
+ bool seen_brace = false;
+ const char *search = p;
+
+ while (search > pattern) {
+ if (!g_ascii_isalnum(*search) && *search != '-') {
+ break;
+ }
+ if (*search == '[' ) {
+ seen_brace = true;
+ break;
+ }
+
+ search --;
+ }
+
+ if (!seen_brace) {
+ /* Escape `-` symbol */
+ *d++ = '\\';
+ }
+ }
+ else if (!(flags & RSPAMD_REGEXP_ESCAPE_RE)) {
+ *d++ = '\\';
+ }
+ break;
case '*':
case '?':
case '+':
@@ -3226,10 +3255,8 @@ rspamd_str_regexp_escape (const gchar *pattern, gsize slen,
/* Treat * as .* and ? as .? */
*d++ = '.';
}
- else {
- if (!(flags & RSPAMD_REGEXP_ESCAPE_RE)) {
- *d++ = '\\';
- }
+ else if (!(flags & RSPAMD_REGEXP_ESCAPE_RE)) {
+ *d++ = '\\';
}
break;
default:
More information about the Commits
mailing list