Browse Source

[Minor] Glob patterns actually allow ranges

tags/3.3
Vsevolod Stakhov 1 year ago
parent
commit
228c83425d
No account linked to committer's email address
1 changed files with 32 additions and 5 deletions
  1. 32
    5
      src/libutil/str_util.c

+ 32
- 5
src/libutil/str_util.c View File

switch (t) { switch (t) {
case '[': case '[':
case ']': case ']':
case '-':
case '\\': case '\\':
case '{': case '{':
case '}': case '}':
*d++ = '\\'; *d++ = '\\';
} }
break; 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 '?': case '?':
case '+': case '+':
/* Treat * as .* and ? as .? */ /* Treat * as .* and ? as .? */
*d++ = '.'; *d++ = '.';
} }
else {
if (!(flags & RSPAMD_REGEXP_ESCAPE_RE)) {
*d++ = '\\';
}
else if (!(flags & RSPAMD_REGEXP_ESCAPE_RE)) {
*d++ = '\\';
} }
break; break;
default: default:

Loading…
Cancel
Save