Skip to content

Commit f6ca597

Browse files
committed
Avoid spamming too many deprecations while parsing
1 parent fa0671c commit f6ca597

3 files changed

Lines changed: 86 additions & 76 deletions

File tree

ext/json/ext/parser/parser.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ typedef struct JSON_ParserStateStruct {
364364
rvalue_cache name_cache;
365365
int in_array;
366366
int current_nesting;
367+
unsigned int emitted_deprecations;
367368
} JSON_ParserState;
368369

369370
static inline size_t rest(JSON_ParserState *state) {
@@ -945,7 +946,12 @@ static inline VALUE json_decode_object(JSON_ParserState *state, JSON_ParserConfi
945946
case JSON_IGNORE:
946947
break;
947948
case JSON_DEPRECATED:
948-
emit_duplicate_key_warning(state, json_find_duplicated_key(count, pairs));
949+
// Only emit the first few deprecations to avoid spamming.
950+
if (state->emitted_deprecations < 5) {
951+
emit_duplicate_key_warning(state, json_find_duplicated_key(count, pairs));
952+
state->emitted_deprecations++;
953+
}
954+
949955
break;
950956
case JSON_RAISE:
951957
raise_duplicate_key_error(state, json_find_duplicated_key(count, pairs));

0 commit comments

Comments
 (0)