Fix crash on unterminated alternation in query

Fixes #968
This commit is contained in:
Max Brunsfeld 2021-03-07 08:48:03 -08:00
parent f18c36ca62
commit 5a2534ac4a
2 changed files with 13 additions and 0 deletions

View file

@ -118,6 +118,18 @@ fn test_query_errors_on_invalid_syntax() {
]
.join("\n")
);
// tree-sitter/tree-sitter/issues/968
assert_eq!(
Query::new(get_language("c"), r#"(parameter_list [ ")" @foo)"#)
.unwrap_err()
.message,
[
r#"(parameter_list [ ")" @foo)"#,
r#" ^"#
]
.join("\n")
);
});
}

View file

@ -1541,6 +1541,7 @@ static TSQueryError ts_query__parse_pattern(
stream_advance(stream);
break;
} else if (e) {
if (e == PARENT_DONE) e = TSQueryErrorSyntax;
array_delete(&branch_step_indices);
return e;
}