diff options
author | Valentin Bartenev <vbart@nginx.com> | 2020-02-20 17:58:24 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2020-02-20 17:58:24 +0300 |
commit | 044b3afcdab3bc434f9340e97e83e37c5227be36 (patch) | |
tree | fff515ff0d35144b780849e5253714bf92737277 /src/nxt_conf.c | |
parent | 7a0383189ca8da1c227dad7a8258b0c4976e105e (diff) | |
download | unit-044b3afcdab3bc434f9340e97e83e37c5227be36.tar.gz unit-044b3afcdab3bc434f9340e97e83e37c5227be36.tar.bz2 |
Configuration: stripping comments from the input JSON.
This allows to have JavaScript-like comments in the uploading JSON.
Diffstat (limited to 'src/nxt_conf.c')
-rw-r--r-- | src/nxt_conf.c | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/src/nxt_conf.c b/src/nxt_conf.c index 43820d2a..2a952c35 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -1244,15 +1244,74 @@ nxt_conf_json_parse(nxt_mp_t *mp, u_char *start, u_char *end, static u_char * nxt_conf_json_skip_space(u_char *start, u_char *end) { - u_char *p; + u_char *p, ch; + + enum { + sw_normal = 0, + sw_after_slash, + sw_single_comment, + sw_multi_comment, + sw_after_asterisk, + } state; + + state = sw_normal; for (p = start; nxt_fast_path(p != end); p++) { + ch = *p; + + switch (state) { + + case sw_normal: + switch (ch) { + case ' ': + case '\t': + case '\n': + case '\r': + continue; + case '/': + state = sw_after_slash; + continue; + } + + break; + + case sw_after_slash: + switch (ch) { + case '/': + state = sw_single_comment; + continue; + case '*': + state = sw_multi_comment; + continue; + } + + p--; + break; + + case sw_single_comment: + if (ch == '\n') { + state = sw_normal; + } - switch (*p) { - case ' ': - case '\t': - case '\r': - case '\n': + continue; + + case sw_multi_comment: + if (ch == '*') { + state = sw_after_asterisk; + } + + continue; + + case sw_after_asterisk: + switch (ch) { + case '/': + state = sw_normal; + continue; + case '*': + continue; + } + + state = sw_multi_comment; continue; } @@ -1346,6 +1405,7 @@ nxt_conf_json_parse_value(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, case '{': case '[': case '"': + case '/': return p; } } |