fix(rust): prevent overflow in error message calculation
**Problem:** When encountering an invalid symbol at the beginning of the file, the rust bindings attempt to index the character at position -1 of the query source, which leads to an overflow and thus invalid character index which causes a panic. **Solution:** Bounds check the offset before performing the subtraction.
This commit is contained in:
parent
c18d019db0
commit
dff828cdbe
2 changed files with 11 additions and 1 deletions
|
|
@ -342,6 +342,16 @@ fn test_query_errors_on_invalid_symbols() {
|
|||
message: "\"alternatives\"".to_string()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
Query::new(&language, "fakefield: (identifier)").unwrap_err(),
|
||||
QueryError {
|
||||
row: 0,
|
||||
offset: 0,
|
||||
column: 0,
|
||||
kind: QueryErrorKind::Field,
|
||||
message: "\"fakefield\"".to_string()
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue