diff options
author | Jean Boussier <[email protected]> | 2025-05-12 13:34:13 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-05-13 14:12:22 +0900 |
commit | 50ef208369c683346340d6dfdc151d4dfceb998d () | |
tree | 8e1e7917a9d2142d1dd055ddb5b2608af8aa7beb /ext/json/parser | |
parent | 8f008598c3be85ee210317236e07cef92296c191 (diff) |
[ruby/json] parser.c: include line and column in error messages
https://.com/ruby/json/commit/30e35b9ba5
Notes: Merged: https://.com/ruby/ruby/pull/13310
-rw-r--r-- | ext/json/parser/parser.c | 42 |
1 files changed, 33 insertions, 9 deletions
@@ -395,6 +395,23 @@ static void raise_parse_error(const char *format, JSON_ParserState *state) { unsigned char buffer[PARSE_ERROR_FRAGMENT_LEN + 1]; const char *ptr = state->cursor; size_t len = ptr ? strnlen(ptr, PARSE_ERROR_FRAGMENT_LEN) : 0; @@ -413,7 +430,14 @@ static void raise_parse_error(const char *format, JSON_ParserState *state) ptr = (const char *)buffer; } - rb_enc_raise(enc_utf8, rb_path2class("JSON::ParserError"), format, ptr); } #ifdef RBIMPL_ATTR_NORETURN @@ -508,11 +532,11 @@ json_eat_comments(JSON_ParserState *state) break; } default: - raise_parse_error("unexpected token at '%s'", state); break; } } else { - raise_parse_error("unexpected token at '%s'", state); } } @@ -870,7 +894,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) return json_push_value(state, config, Qnil); } - raise_parse_error("unexpected token at '%s'", state); break; case 't': if ((state->end - state->cursor >= 4) && (memcmp(state->cursor, "true", 4) == 0)) { @@ -878,7 +902,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) return json_push_value(state, config, Qtrue); } - raise_parse_error("unexpected token at '%s'", state); break; case 'f': // Note: memcmp with a small power of two compile to an integer comparison @@ -887,7 +911,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) return json_push_value(state, config, Qfalse); } - raise_parse_error("unexpected token at '%s'", state); break; case 'N': // Note: memcmp with a small power of two compile to an integer comparison @@ -896,7 +920,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) return json_push_value(state, config, CNaN); } - raise_parse_error("unexpected token at '%s'", state); break; case 'I': if (config->allow_nan && (state->end - state->cursor >= 8) && (memcmp(state->cursor, "Infinity", 8) == 0)) { @@ -904,7 +928,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) return json_push_value(state, config, CInfinity); } - raise_parse_error("unexpected token at '%s'", state); break; case '-': // Note: memcmp with a small power of two compile to an integer comparison @@ -913,7 +937,7 @@ static VALUE json_parse_any(JSON_ParserState *state, JSON_ParserConfig *config) state->cursor += 9; return json_push_value(state, config, CMinusInfinity); } else { - raise_parse_error("unexpected token at '%s'", state); } } // Fallthrough |