mirror of
https://github.com/helix-editor/helix.git
synced 2024-08-17 06:40:47 +03:00
Fix panic in select_textobject_around (#9832)
Test Document ------------- ``` a)b ``` Steps to Reproduce ------------------ 1. % # select_all 1. ms( # surround_add 1. mam # select_textobject_around Debug and Release ----------------- `thread 'main' panicked at 'Attempt to index past end of RopeSlice: char index 7, RopeSlice char length 6', ropey-1.6.1/src/slice.rs:796:13` Description ----------- An index was selected beyond the end of the slice with chars_at. The fix adds a guard check to `find_nth_open_pair`, like in the other find_nth* functions.
This commit is contained in:
parent
cb01e52cd8
commit
e27b04735c
@ -167,6 +167,10 @@ fn find_nth_open_pair(
|
||||
mut pos: usize,
|
||||
n: usize,
|
||||
) -> Option<usize> {
|
||||
if pos >= text.len_chars() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut chars = text.chars_at(pos + 1);
|
||||
|
||||
// Adjusts pos for the first iteration, and handles the case of the
|
||||
@ -383,6 +387,21 @@ fn test_find_nth_pairs_pos_inside_quote_ambiguous() {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_nth_closest_pairs_pos_index_range_panic() {
|
||||
#[rustfmt::skip]
|
||||
let (doc, selection, _) =
|
||||
rope_with_selections_and_expectations(
|
||||
"(a)c)",
|
||||
"^^^^^"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
find_nth_closest_pairs_pos(doc.slice(..), selection.primary(), 1),
|
||||
Err(Error::PairNotFound)
|
||||
)
|
||||
}
|
||||
|
||||
// Create a Rope and a matching Selection using a specification language.
|
||||
// ^ is a single-point selection.
|
||||
// _ is an expected index. These are returned as a Vec<usize> for use in assertions.
|
||||
|
Loading…
Reference in New Issue
Block a user