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:
Riley Bruins 2025-07-21 21:44:21 -07:00 committed by Christian Clason
parent c18d019db0
commit dff828cdbe
2 changed files with 11 additions and 1 deletions

View file

@ -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()
}
);
});
}