diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 5c37a9ab..2ac178fc 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -31,9 +31,10 @@ fn test_query_errors_on_invalid_syntax() { Err(QueryError::Syntax(24)) ); + // Return an error at the beginning of an unterminated string. assert_eq!( - Query::new(language, "(if_statement condition:)"), - Err(QueryError::Syntax(24)) + Query::new(language, r#"(identifier) "h "#), + Err(QueryError::Syntax(13)) ); }); } diff --git a/lib/src/query.c b/lib/src/query.c index ea01cf24..10d409ed 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -398,7 +398,12 @@ static TSQueryError ts_query_parse_pattern( // Parse the string content const char *string_content = stream->input; - while (stream->next && stream->next != '"') stream_advance(stream); + while (stream->next != '"') { + if (!stream_advance(stream)) { + stream_reset(stream, string_content - 1); + return TSQueryErrorSyntax; + } + } uint32_t length = stream->input - string_content; // Add a step for the node