From 844174367b66a09e9caae975f19c11df0bdf3b81 Mon Sep 17 00:00:00 2001 From: Neeraj Jaiswal Date: Sat, 18 Feb 2023 21:53:04 +0530 Subject: [PATCH] wgetopt: fix long option match to always match prefix --- fish-rust/src/wgetopt.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fish-rust/src/wgetopt.rs b/fish-rust/src/wgetopt.rs index c4129d90a..f2e98405d 100644 --- a/fish-rust/src/wgetopt.rs +++ b/fish-rust/src/wgetopt.rs @@ -450,19 +450,22 @@ fn _find_matching_long_opt( // Test all long options for either exact match or abbreviated matches. for (option_index, p) in self.longopts.iter().enumerate() { + // Check if current option is prefix of long opt if p.name.starts_with(&self.nextchar[..nameend]) { - // Exact match found. - pfound = Some(*p); - *indfound = option_index; - *exact = true; - break; - } else if pfound.is_none() { - // First nonexact match found. - pfound = Some(*p); - *indfound = option_index; - } else { - // Second or later nonexact match found. - *ambig = true; + if nameend == p.name.len() { + // The current option is exact match of this long option + pfound = Some(*p); + *indfound = option_index; + *exact = true; + break; + } else if pfound.is_none() { + // current option is first prefix match but not exact match + pfound = Some(*p); + *indfound = option_index; + } else { + // current option is second or later prefix match but not exact match + *ambig = true; + } } } return pfound;