File tree Expand file tree Collapse file tree 4 files changed +15
-4
lines changed
test/fixtures/error_corpus Expand file tree Collapse file tree 4 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -266,6 +266,17 @@ fn test_parsing_invalid_chars_at_eof() {
266266 assert_eq ! ( tree. root_node( ) . to_sexp( ) , "(ERROR (UNEXPECTED INVALID))" ) ;
267267}
268268
269+ #[ test]
270+ fn test_parsing_unexpected_null_characters_within_source ( ) {
271+ let mut parser = Parser :: new ( ) ;
272+ parser. set_language ( get_language ( "javascript" ) ) . unwrap ( ) ;
273+ let tree = parser. parse ( b"var \0 something;" , None ) . unwrap ( ) ;
274+ assert_eq ! (
275+ tree. root_node( ) . to_sexp( ) ,
276+ "(program (variable_declaration (ERROR (UNEXPECTED '\\ 0')) (variable_declarator name: (identifier))))"
277+ ) ;
278+ }
279+
269280#[ test]
270281fn test_parsing_ends_when_input_callback_returns_empty ( ) {
271282 let mut parser = Parser :: new ( ) ;
Original file line number Diff line number Diff line change @@ -439,7 +439,7 @@ static Subtree ts_parser__lex(
439439 }
440440
441441 if (self -> lexer .current_position .bytes == error_end_position .bytes ) {
442- if (self -> lexer .data .lookahead == 0 ) {
442+ if (self -> lexer .data .eof ( & self -> lexer . data ) ) {
443443 self -> lexer .data .result_symbol = ts_builtin_sym_error ;
444444 break ;
445445 }
Original file line number Diff line number Diff line change @@ -766,10 +766,10 @@ Subtree ts_subtree_last_external_token(Subtree tree) {
766766}
767767
768768static size_t ts_subtree__write_char_to_string (char * s , size_t n , int32_t c ) {
769- if (c == 0 )
770- return snprintf (s , n , "EOF" );
771769 if (c == -1 )
772770 return snprintf (s , n , "INVALID" );
771+ else if (c == '\0' )
772+ return snprintf (s , n , "'\\0'" );
773773 else if (c == '\n' )
774774 return snprintf (s , n , "'\\n'" );
775775 else if (c == '\t' )
Original file line number Diff line number Diff line change @@ -65,4 +65,4 @@ incomplete tokens at EOF
6565nul
6666---
6767
68- (ERROR (UNEXPECTED EOF ))
68+ (ERROR (UNEXPECTED '\0' ))
You can’t perform that action at this time.
0 commit comments