File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -476,7 +476,7 @@ static const bool whitespace[256] = {
476476 ['/' ] = 1 ,
477477};
478478
479- static bool
479+ static void
480480json_eat_comments (JSON_ParserState * state )
481481{
482482 if (state -> cursor + 1 < state -> end ) {
@@ -496,7 +496,7 @@ json_eat_comments(JSON_ParserState *state)
496496 state -> cursor = memchr (state -> cursor , '*' , state -> end - state -> cursor );
497497 if (!state -> cursor ) {
498498 state -> cursor = state -> end ;
499- break ;
499+ raise_parse_error ( "unexpected end of input, expected closing '*/'" , state -> cursor ) ;
500500 } else {
501501 state -> cursor ++ ;
502502 if (state -> cursor < state -> end && * state -> cursor == '/' ) {
@@ -508,10 +508,12 @@ json_eat_comments(JSON_ParserState *state)
508508 break ;
509509 }
510510 default :
511- return false;
511+ raise_parse_error ("unexpected token at '%s'" , state -> cursor );
512+ break ;
512513 }
514+ } else {
515+ raise_parse_error ("unexpected token at '%s'" , state -> cursor );
513516 }
514- return true;
515517}
516518
517519static inline void
@@ -521,9 +523,7 @@ json_eat_whitespace(JSON_ParserState *state)
521523 if (RB_LIKELY (* state -> cursor != '/' )) {
522524 state -> cursor ++ ;
523525 } else {
524- if (!json_eat_comments (state )) {
525- return ;
526- }
526+ json_eat_comments (state );
527527 }
528528 }
529529}
Original file line number Diff line number Diff line change @@ -406,6 +406,11 @@ def test_parse_comments
406406 }
407407 JSON
408408 assert_equal ( { "key1" => "value1" } , parse ( json ) )
409+ assert_equal ( { } , parse ( '{} /**/' ) )
410+ assert_raise ( ParserError ) { parse ( '{} /* comment not closed' ) }
411+ assert_raise ( ParserError ) { parse ( '{} /*/' ) }
412+ assert_raise ( ParserError ) { parse ( '{} /x wrong comment' ) }
413+ assert_raise ( ParserError ) { parse ( '{} /' ) }
409414 end
410415
411416 def test_nesting
You can’t perform that action at this time.
0 commit comments