Skip to content

Commit

Permalink
fix(expansion): handle negative substring offset (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored Feb 1, 2025
1 parent d8a57de commit c7164d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion brush-core/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ impl Config {
// Make a best-effort attempt to tokenize.
let tokens = Self::tokenize_input_for_completion(shell, input);

let cursor: i32 = i32::try_from(position)?;
let cursor = i32::try_from(position)?;
let mut preceding_token = None;
let mut completion_prefix = "";
let mut insertion_index = cursor;
Expand Down
6 changes: 5 additions & 1 deletion brush-core/src/expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,11 @@ impl<'a> WordExpander<'a> {
}

let expanded_offset = offset.eval(self.shell, false).await?;
let expanded_offset = usize::try_from(expanded_offset)?;
let expanded_offset = if expanded_offset < 0 {
0
} else {
usize::try_from(expanded_offset)?
};

let expanded_parameter_len = expanded_parameter.polymorphic_len();
let expanded_offset = min(expanded_offset, expanded_parameter_len);
Expand Down

0 comments on commit c7164d7

Please sign in to comment.