diff options
author | Valentin Bartenev <vbart@nginx.com> | 2017-07-07 18:09:15 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2017-07-07 18:09:15 +0300 |
commit | fc9f73bbea940b003824aec914bf6ea948c09252 (patch) | |
tree | 1c84c31b43e8b95f1d7d613b92bfcf9f6fa28ea0 /src | |
parent | 9a402ea83d24ab4e380298a5718e7c4bf1a76219 (diff) | |
download | unit-fc9f73bbea940b003824aec914bf6ea948c09252.tar.gz unit-fc9f73bbea940b003824aec914bf6ea948c09252.tar.bz2 |
Controller: relaxed JSON parser.
Now it allows commas after the last elements in objects and arrays,
as it's a common Igor's mistake.
Diffstat (limited to 'src')
-rw-r--r-- | src/nxt_conf.c | 152 |
1 files changed, 72 insertions, 80 deletions
diff --git a/src/nxt_conf.c b/src/nxt_conf.c index f891f71e..935afab9 100644 --- a/src/nxt_conf.c +++ b/src/nxt_conf.c @@ -939,12 +939,6 @@ nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, nxt_conf_object_t *object; nxt_conf_object_member_t *member, *element; - p = nxt_conf_json_skip_space(start + 1, end); - - if (nxt_slow_path(p == end)) { - return NULL; - } - mp_temp = nxt_mp_create(1024, 128, 256, 32); if (nxt_slow_path(mp_temp == NULL)) { return NULL; @@ -953,70 +947,72 @@ nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, nxt_lvlhsh_init(&hash); count = 0; + p = start; - if (*p != '}') { - - for ( ;; ) { - count++; + for ( ;; ) { + p = nxt_conf_json_skip_space(p + 1, end); - if (*p != '"') { - goto error; - } + if (nxt_slow_path(p == end)) { + goto error; + } - member = nxt_mp_get(mp_temp, sizeof(nxt_conf_object_member_t)); - if (nxt_slow_path(member == NULL)) { - goto error; + if (*p != '"') { + if (nxt_fast_path(*p == '}')) { + break; } - p = nxt_conf_json_parse_string(mp, &member->name, p, end); + goto error; + } - if (nxt_slow_path(p == NULL)) { - goto error; - } + count++; - rc = nxt_conf_object_hash_add(mp_temp, &hash, member); + member = nxt_mp_get(mp_temp, sizeof(nxt_conf_object_member_t)); + if (nxt_slow_path(member == NULL)) { + goto error; + } - if (nxt_slow_path(rc != NXT_OK)) { - goto error; - } + p = nxt_conf_json_parse_string(mp, &member->name, p, end); - p = nxt_conf_json_skip_space(p, end); + if (nxt_slow_path(p == NULL)) { + goto error; + } - if (nxt_slow_path(p == end || *p != ':')) { - goto error; - } + rc = nxt_conf_object_hash_add(mp_temp, &hash, member); - p = nxt_conf_json_skip_space(p + 1, end); + if (nxt_slow_path(rc != NXT_OK)) { + goto error; + } - if (nxt_slow_path(p == end)) { - goto error; - } + p = nxt_conf_json_skip_space(p, end); - p = nxt_conf_json_parse_value(mp, &member->value, p, end); + if (nxt_slow_path(p == end || *p != ':')) { + goto error; + } - if (nxt_slow_path(p == NULL)) { - goto error; - } + p = nxt_conf_json_skip_space(p + 1, end); - p = nxt_conf_json_skip_space(p, end); + if (nxt_slow_path(p == end)) { + goto error; + } - if (nxt_slow_path(p == end)) { - goto error; - } + p = nxt_conf_json_parse_value(mp, &member->value, p, end); - if (*p == '}') { - break; - } + if (nxt_slow_path(p == NULL)) { + goto error; + } - if (nxt_slow_path(*p != ',')) { - goto error; - } + p = nxt_conf_json_skip_space(p, end); - p = nxt_conf_json_skip_space(p + 1, end); + if (nxt_slow_path(p == end)) { + goto error; + } - if (nxt_slow_path(p == end)) { - goto error; + if (*p != ',') { + if (nxt_fast_path(*p == '}')) { + break; } + + goto error; } } @@ -1117,12 +1113,6 @@ nxt_conf_json_parse_array(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, nxt_conf_array_t *array; nxt_conf_value_t *element; - p = nxt_conf_json_skip_space(start + 1, end); - - if (nxt_slow_path(p == end)) { - return NULL; - } - mp_temp = nxt_mp_create(1024, 128, 256, 32); if (nxt_slow_path(mp_temp == NULL)) { return NULL; @@ -1134,42 +1124,44 @@ nxt_conf_json_parse_array(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start, } count = 0; + p = start; - if (*p != ']') { - - for ( ;; ) { - count++; + for ( ;; ) { + p = nxt_conf_json_skip_space(p + 1, end); - element = nxt_list_add(list); - if (nxt_slow_path(element == NULL)) { - goto error; - } + if (nxt_slow_path(p == end)) { + goto error; + } - p = nxt_conf_json_parse_value(mp, element, p, end); + if (*p == ']') { + break; + } - if (nxt_slow_path(p == NULL)) { - goto error; - } + count++; - p = nxt_conf_json_skip_space(p, end); + element = nxt_list_add(list); + if (nxt_slow_path(element == NULL)) { + goto error; + } - if (nxt_slow_path(p == end)) { - goto error; - } + p = nxt_conf_json_parse_value(mp, element, p, end); - if (*p == ']') { - break; - } + if (nxt_slow_path(p == NULL)) { + goto error; + } - if (nxt_slow_path(*p != ',')) { - goto error; - } + p = nxt_conf_json_skip_space(p, end); - p = nxt_conf_json_skip_space(p + 1, end); + if (nxt_slow_path(p == end)) { + goto error; + } - if (nxt_slow_path(p == end)) { - goto error; + if (*p != ',') { + if (nxt_fast_path(*p == ']')) { + break; } + + goto error; } } |