Controller: relaxed JSON parser.

Now it allows commas after the last elements in objects and arrays,
as it's a common Igor's mistake.
This commit is contained in:
Valentin Bartenev
2017-07-07 18:09:15 +03:00
parent 9a402ea83d
commit fc9f73bbea

View File

@@ -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,16 +947,25 @@ nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
nxt_lvlhsh_init(&hash);
count = 0;
if (*p != '}') {
p = start;
for ( ;; ) {
count++;
p = nxt_conf_json_skip_space(p + 1, end);
if (*p != '"') {
if (nxt_slow_path(p == end)) {
goto error;
}
if (*p != '"') {
if (nxt_fast_path(*p == '}')) {
break;
}
goto error;
}
count++;
member = nxt_mp_get(mp_temp, sizeof(nxt_conf_object_member_t));
if (nxt_slow_path(member == NULL)) {
goto error;
@@ -1004,20 +1007,13 @@ nxt_conf_json_parse_object(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
goto error;
}
if (*p == '}') {
if (*p != ',') {
if (nxt_fast_path(*p == '}')) {
break;
}
if (nxt_slow_path(*p != ',')) {
goto error;
}
p = nxt_conf_json_skip_space(p + 1, end);
if (nxt_slow_path(p == end)) {
goto error;
}
}
}
object = nxt_mp_get(mp, sizeof(nxt_conf_object_t)
@@ -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,10 +1124,19 @@ nxt_conf_json_parse_array(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
}
count = 0;
if (*p != ']') {
p = start;
for ( ;; ) {
p = nxt_conf_json_skip_space(p + 1, end);
if (nxt_slow_path(p == end)) {
goto error;
}
if (*p == ']') {
break;
}
count++;
element = nxt_list_add(list);
@@ -1157,20 +1156,13 @@ nxt_conf_json_parse_array(nxt_mp_t *mp, nxt_conf_value_t *value, u_char *start,
goto error;
}
if (*p == ']') {
if (*p != ',') {
if (nxt_fast_path(*p == ']')) {
break;
}
if (nxt_slow_path(*p != ',')) {
goto error;
}
p = nxt_conf_json_skip_space(p + 1, end);
if (nxt_slow_path(p == end)) {
goto error;
}
}
}
array = nxt_mp_get(mp, sizeof(nxt_conf_array_t)