Added support for wildcards in the middle of match patterns.

This commit is contained in:
Igor Sysoev
2019-04-10 13:47:34 +03:00
parent ac7e65a722
commit 8339b15158
2 changed files with 131 additions and 26 deletions

View File

@@ -741,6 +741,12 @@ nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
nxt_str_t pattern;
nxt_uint_t i, first, last;
enum {
sw_none,
sw_side,
sw_middle
} state;
if (nxt_conf_type(value) != NXT_CONF_STRING) {
return nxt_conf_vldt_error(vldt,
"The \"match\" patterns must be strings.");
@@ -754,17 +760,32 @@ nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
first = (pattern.start[0] == '!');
last = pattern.length - 1;
state = sw_none;
for (i = first; i != pattern.length; i++) {
ch = pattern.start[i];
if (ch != '*') {
continue;
}
if (i != first && i != last) {
return nxt_conf_vldt_error(vldt, "The \"match\" patterns can only "
"contain \"*\" markers at the sides.");
switch (state) {
case sw_none:
state = (i == first) ? sw_side : sw_middle;
break;
case sw_side:
if (i == last) {
break;
}
/* Fall through. */
case sw_middle:
return nxt_conf_vldt_error(vldt, "The \"match\" patterns can "
"either contain \"*\" markers at "
"the sides or only one in the middle.");
}
}