Merge pull request #2280 from smoelius/query-new-oob
Fix OOB in `Query::new`
This commit is contained in:
commit
b4c73a2b0e
2 changed files with 17 additions and 1 deletions
|
|
@ -4575,3 +4575,19 @@ fn test_query_max_start_depth() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_error_does_not_oob() {
|
||||
let language = get_language("javascript");
|
||||
|
||||
assert_eq!(
|
||||
Query::new(language, "(clas").unwrap_err(),
|
||||
QueryError {
|
||||
row: 0,
|
||||
offset: 1,
|
||||
column: 1,
|
||||
kind: QueryErrorKind::NodeType,
|
||||
message: "clas".to_string()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1401,7 +1401,7 @@ impl Query {
|
|||
let suffix = source.split_at(offset).1;
|
||||
let end_offset = suffix
|
||||
.find(|c| !char::is_alphanumeric(c) && c != '_' && c != '-')
|
||||
.unwrap_or(source.len());
|
||||
.unwrap_or(suffix.len());
|
||||
message = suffix.split_at(end_offset).0.to_string();
|
||||
kind = match error_type {
|
||||
ffi::TSQueryError_TSQueryErrorNodeType => QueryErrorKind::NodeType,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue