summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2019-04-10 13:47:34 +0300
committerIgor Sysoev <igor@sysoev.ru>2019-04-10 13:47:34 +0300
commit8339b1515816ec8d3661514dc3edb73874580977 (patch)
treede9b77da32ed2145a5d8285f9273e829e235d871 /src/nxt_conf_validation.c
parentac7e65a722d38786c63716c026ab588e3d205a25 (diff)
downloadunit-8339b1515816ec8d3661514dc3edb73874580977.tar.gz
unit-8339b1515816ec8d3661514dc3edb73874580977.tar.bz2
Added support for wildcards in the middle of match patterns.
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index ee87b0f6..e2e1b89e 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -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.");
}
}