diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 912136cb..f0f37788 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -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() + } + ); +} diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index 87294a5d..f9ec7f67 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -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,