Skip to content

Commit

Permalink
don't crash in plaintext bracket match (mm) on empty file
Browse files Browse the repository at this point in the history
pascalkuthe authored and archseer committed Jan 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3f88a3f commit 2fb7e50
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion helix-core/src/match_brackets.rs
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ fn find_pair(
#[must_use]
pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Option<usize> {
// Don't do anything when the cursor is not on top of a bracket.
let bracket = doc.char(cursor_pos);
let bracket = doc.get_char(cursor_pos)?;
if !is_valid_bracket(bracket) {
return None;
}
@@ -265,6 +265,12 @@ fn as_char(doc: RopeSlice, node: &Node) -> Option<(usize, char)> {
mod tests {
use super::*;

#[test]
fn find_matching_bracket_empty_file() {
let actual = find_matching_bracket_plaintext("".into(), 0);
assert_eq!(actual, None);
}

#[test]
fn test_find_matching_bracket_current_line_plaintext() {
let assert = |input: &str, pos, expected| {

0 comments on commit 2fb7e50

Please sign in to comment.