You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are few legitimate use cases for duplicate keys, and can
in some case be exploited.
Rather to always silently accept them, we should emit a warning,
and in the future require to explictly allow them.
if (RB_UNLIKELY(RHASH_SIZE(object) <entries_count)) {
838
+
switch (config->on_duplicate_key) {
839
+
caseJSON_IGNORE:
840
+
break;
841
+
caseJSON_DEPRECATED:
842
+
emit_parse_warning("detected duplicate keys in JSON object. This will raise an error in json 3.0 unless enabled via `allow_duplicate_key: true`", state);
843
+
break;
844
+
caseJSON_RAISE:
845
+
raise_parse_error("duplicate key", state);
846
+
break;
847
+
}
848
+
}
849
+
815
850
rvalue_stack_pop(state->stack, count);
816
851
817
852
if (config->freeze) {
@@ -1060,6 +1095,8 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
1060
1095
break;
1061
1096
}
1062
1097
case'{': {
1098
+
constchar*object_start_cursor=state->cursor;
1099
+
1063
1100
state->cursor++;
1064
1101
json_eat_whitespace(state);
1065
1102
longstack_head=state->stack->head;
@@ -1094,8 +1131,15 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config)
0 commit comments