summaryrefslogtreecommitdiff
path: root/ext/json/parser
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-10-21 22:19:44 +0200
committerHiroshi SHIBATA <[email protected]>2024-10-26 18:44:15 +0900
commitfc9f0cb8c5ead74455370f2ae409bc4a6b1dedc0 ()
treef289961afc78ca5903e306e7d17cad870f3e9a46 /ext/json/parser
parent2c6e3bc71e12e12ad6949502e2b161171ca56840 (diff)
[ruby/json] JSON.dump / String#to_json: raise on invalid encoding
This regressed since 2.7.2. https://.com/ruby/json/commit/35407d6635
-rw-r--r--ext/json/parser/parser.c19
-rw-r--r--ext/json/parser/parser.rl3
2 files changed, 14 insertions, 8 deletions
@@ -1794,6 +1794,9 @@ static VALUE convert_encoding(VALUE source)
}
if (encindex == binary_encindex) {
return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
}
@@ -1943,7 +1946,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
}
-#line 1947 "parser.c"
enum {JSON_start = 1};
enum {JSON_first_final = 10};
enum {JSON_error = 0};
@@ -1951,7 +1954,7 @@ enum {JSON_error = 0};
enum {JSON_en_main = 1};
-#line 855 "parser.rl"
/*
@@ -1969,16 +1972,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1973 "parser.c"
{
cs = JSON_start;
}
-#line 872 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1982 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -2012,7 +2015,7 @@ st0:
cs = 0;
goto _out;
tr2:
-#line 847 "parser.rl"
{
char *np = JSON_parse_value(json, p, pe, &result, 0);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -2022,7 +2025,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 2026 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -2111,7 +2114,7 @@ case 9:
_out: {}
}
-#line 875 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -689,6 +689,9 @@ static VALUE convert_encoding(VALUE source)
}
if (encindex == binary_encindex) {
return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
}