From 7d3feeae9a7e1d543a94747b3de8f07ee1128daa Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 2 Oct 2025 17:21:50 +0200 Subject: [PATCH] cli: Do not validate UTF-8 boundaries when query results are not being tested Co-authored-by: Kirill Bulatov Co-authored-by: dino Co-authored-by: Max Brunsfeld Co-authored-by: John Tur --- crates/cli/src/query.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/cli/src/query.rs b/crates/cli/src/query.rs index fec85bd2..7343049f 100644 --- a/crates/cli/src/query.rs +++ b/crates/cli/src/query.rs @@ -80,11 +80,13 @@ pub fn query_file_at_path( capture.node.utf8_text(&source_code).unwrap_or("") )?; } - results.push(query_testing::CaptureInfo { - name: (*capture_name).to_string(), - start: to_utf8_point(capture.node.start_position(), source_code.as_slice()), - end: to_utf8_point(capture.node.end_position(), source_code.as_slice()), - }); + if should_test { + results.push(query_testing::CaptureInfo { + name: (*capture_name).to_string(), + start: to_utf8_point(capture.node.start_position(), source_code.as_slice()), + end: to_utf8_point(capture.node.end_position(), source_code.as_slice()), + }); + } } } else { let mut matches = query_cursor.matches(&query, tree.root_node(), source_code.as_slice()); @@ -111,11 +113,13 @@ pub fn query_file_at_path( )?; } } - results.push(query_testing::CaptureInfo { - name: (*capture_name).to_string(), - start: to_utf8_point(capture.node.start_position(), source_code.as_slice()), - end: to_utf8_point(capture.node.end_position(), source_code.as_slice()), - }); + if should_test { + results.push(query_testing::CaptureInfo { + name: (*capture_name).to_string(), + start: to_utf8_point(capture.node.start_position(), source_code.as_slice()), + end: to_utf8_point(capture.node.end_position(), source_code.as_slice()), + }); + } } } }