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] = {
476
476
['/' ] = 1 ,
477
477
};
478
478
479
- static bool
479
+ static void
480
480
json_eat_comments (JSON_ParserState * state )
481
481
{
482
482
if (state -> cursor + 1 < state -> end ) {
@@ -496,7 +496,7 @@ json_eat_comments(JSON_ParserState *state)
496
496
state -> cursor = memchr (state -> cursor , '*' , state -> end - state -> cursor );
497
497
if (!state -> cursor ) {
498
498
state -> cursor = state -> end ;
499
- break ;
499
+ raise_parse_error ( "unexpected end of input, expected closing '*/'" , state -> cursor ) ;
500
500
} else {
501
501
state -> cursor ++ ;
502
502
if (state -> cursor < state -> end && * state -> cursor == '/' ) {
@@ -508,10 +508,12 @@ json_eat_comments(JSON_ParserState *state)
508
508
break ;
509
509
}
510
510
default :
511
- return false;
511
+ raise_parse_error ("unexpected token at '%s'" , state -> cursor );
512
+ break ;
512
513
}
514
+ } else {
515
+ raise_parse_error ("unexpected token at '%s'" , state -> cursor );
513
516
}
514
- return true;
515
517
}
516
518
517
519
static inline void
@@ -521,9 +523,7 @@ json_eat_whitespace(JSON_ParserState *state)
521
523
if (RB_LIKELY (* state -> cursor != '/' )) {
522
524
state -> cursor ++ ;
523
525
} else {
524
- if (!json_eat_comments (state )) {
525
- return ;
526
- }
526
+ json_eat_comments (state );
527
527
}
528
528
}
529
529
}
Original file line number Diff line number Diff line change @@ -406,6 +406,11 @@ def test_parse_comments
406
406
}
407
407
JSON
408
408
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 ( '{} /' ) }
409
414
end
410
415
411
416
def test_nesting
You can’t perform that action at this time.
0 commit comments