From 92353a2d2193374677d611913f610bfff40bb3d8 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 15 Jan 2025 16:05:24 +0100 Subject: [PATCH] Add symbolize_names support --- ext/json/ext/parser/parser.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index c0228c6b..e8051608 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -715,19 +715,20 @@ json_decode_float(JSON_ParserState *state, const char *start, const char *end) #define PUSH(result) rvalue_stack_push(state->stack, result, &state->stack_handle, &state->stack) static inline VALUE -json_parse_string(JSON_ParserState *state) { +json_parse_string(JSON_ParserState *state, bool is_name) { state->cursor++; const char *start = state->cursor; bool escaped = false; while (state->cursor < state->end) { if (*state->cursor == '"') { - // TODO: bool is_name, bool intern, bool symbolize VALUE string; + bool intern = is_name || state->json->freeze; + bool symbolize = is_name && state->json->symbolize_names; if (escaped) { - string = json_string_unescape(state, start, state->cursor, false, false, false); + string = json_string_unescape(state, start, state->cursor, is_name, intern, symbolize); } else { - string = json_string_fastpath(state, start, state->cursor, false, false, false); + string = json_string_fastpath(state, start, state->cursor, is_name, intern, symbolize); } state->cursor++; return PUSH(string); @@ -811,7 +812,7 @@ json_parse_any(JSON_ParserState *state) { } case '"': { // %r{\A"[^"\\\t\n\x00]*(?:\\[bfnrtu\\/"][^"\\]*)*"} - return json_parse_string(state); + return json_parse_string(state, false); break; } case '[': { @@ -863,7 +864,7 @@ json_parse_any(JSON_ParserState *state) { if (*state->cursor != '"') { raise_parse_error("expected object key", state->cursor); } - json_parse_string(state); + json_parse_string(state, true); json_eat_whitespace(state);