@@ -7,8 +7,9 @@ static VALUE CNaN, CInfinity, CMinusInfinity;
77
88static ID i_new , i_try_convert , i_uminus , i_encode ;
99
10- static VALUE sym_max_nesting , sym_allow_nan , sym_allow_trailing_comma , sym_allow_control_characters , sym_symbolize_names , sym_freeze ,
11- sym_decimal_class , sym_on_load , sym_allow_duplicate_key ;
10+ static VALUE sym_max_nesting , sym_allow_nan , sym_allow_trailing_comma , sym_allow_control_characters ,
11+ sym_allow_invalid_escape , sym_symbolize_names , sym_freeze , sym_decimal_class , sym_on_load ,
12+ sym_allow_duplicate_key ;
1213
1314static int binary_encindex ;
1415static int utf8_encindex ;
@@ -336,6 +337,7 @@ typedef struct JSON_ParserStruct {
336337 bool allow_nan ;
337338 bool allow_trailing_comma ;
338339 bool allow_control_characters ;
340+ bool allow_invalid_escape ;
339341 bool symbolize_names ;
340342 bool freeze ;
341343} JSON_ParserConfig ;
@@ -746,6 +748,8 @@ NOINLINE(static) VALUE json_string_unescape(JSON_ParserState *state, JSON_Parser
746748 }
747749 raise_parse_error_at ("invalid ASCII control character in string: %s" , state , pe - 1 );
748750 }
751+ } else if (config -> allow_invalid_escape ) {
752+ APPEND_CHAR (* pe );
749753 } else {
750754 raise_parse_error_at ("invalid escape character in string: %s" , state , pe - 1 );
751755 }
@@ -1435,6 +1439,7 @@ static int parser_config_init_i(VALUE key, VALUE val, VALUE data)
14351439 else if (key == sym_allow_nan ) { config -> allow_nan = RTEST (val ); }
14361440 else if (key == sym_allow_trailing_comma ) { config -> allow_trailing_comma = RTEST (val ); }
14371441 else if (key == sym_allow_control_characters ) { config -> allow_control_characters = RTEST (val ); }
1442+ else if (key == sym_allow_invalid_escape ) { config -> allow_invalid_escape = RTEST (val ); }
14381443 else if (key == sym_symbolize_names ) { config -> symbolize_names = RTEST (val ); }
14391444 else if (key == sym_freeze ) { config -> freeze = RTEST (val ); }
14401445 else if (key == sym_on_load ) { config -> on_load_proc = RTEST (val ) ? val : Qfalse ; }
@@ -1653,6 +1658,7 @@ void Init_parser(void)
16531658 sym_allow_nan = ID2SYM (rb_intern ("allow_nan" ));
16541659 sym_allow_trailing_comma = ID2SYM (rb_intern ("allow_trailing_comma" ));
16551660 sym_allow_control_characters = ID2SYM (rb_intern ("allow_control_characters" ));
1661+ sym_allow_invalid_escape = ID2SYM (rb_intern ("allow_invalid_escape" ));
16561662 sym_symbolize_names = ID2SYM (rb_intern ("symbolize_names" ));
16571663 sym_freeze = ID2SYM (rb_intern ("freeze" ));
16581664 sym_on_load = ID2SYM (rb_intern ("on_load" ));
0 commit comments