Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buffer overflow in completion example #169

Merged
merged 2 commits into from Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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<_>>();
bryanhitc marked this conversation as resolved.
Show resolved Hide resolved

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