Skip to content

Commit

Permalink
Merge pull request #169 from bryanhitc/bryanhitc/fix-completion-buffe…
Browse files Browse the repository at this point in the history
…r-overflow

Fix buffer overflow in completion example
  • Loading branch information
pksunkara committed Feb 11, 2022
2 parents 29da763 + e4ffea8 commit dee84e9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/completion.rs
Expand Up @@ -29,10 +29,14 @@ impl Default for MyCompletion {
impl Completion for MyCompletion {
/// Simple completion implementation based on substring
fn get(&self, input: &str) -> Option<String> {
let s = input.to_string();
let ss: Vec<&String> = self.options.iter().filter(|x| s == x[..s.len()]).collect();
if ss.len() == 1 {
Some(ss[0].to_string())
let matches = self
.options
.iter()
.filter(|option| option.starts_with(input))
.collect::<Vec<_>>();

if matches.len() == 1 {
Some(matches[0].to_string())
} else {
None
}
Expand Down

0 comments on commit dee84e9

Please sign in to comment.