Skip to content

Commit 74800b4

Browse files
authored
Do not search for combined flags in long options.
1 parent b3ca1e9 commit 74800b4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ impl Arguments {
173173
true
174174
} else {
175175
#[cfg(feature = "combined-flags")]
176-
// Combined flags only work of the short flag is a single character
176+
// Combined flags only work if the short flag is a single character
177177
{
178178
if keys.first().len() == 2 {
179179
let short_flag = &keys.first()[1..2];
180180
for (n, item) in self.0.iter().enumerate() {
181181
if let Some(s) = item.to_str() {
182-
if s.starts_with('-') && s.contains(short_flag) {
182+
if s.starts_with('-') && !s.starts_with("--") && s.contains(short_flag) {
183183
if s.len() == 2 {
184184
// last flag
185185
self.0.remove(n);

tests/tests.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ fn combined_flags_leftover() {
230230
assert_eq!(args.finish(), vec![OsString::from("-b")]);
231231
}
232232

233+
#[test]
234+
fn long_flag_with_character_from_short_flag() {
235+
let mut args = Arguments::from_vec(to_vec(&["--version"]));
236+
assert!(!args.contains("-s"));
237+
assert!(args.contains("--version"));
238+
}
239+
240+
#[cfg(feature = "combined-flags")]
241+
#[test]
242+
fn combined_long_flag_with_character_from_short_flag() {
243+
let mut args = Arguments::from_vec(to_vec(&["--version"]));
244+
assert!(!args.contains("-s"));
245+
assert!(args.contains("--version"));
246+
}
247+
233248
#[cfg(feature = "short-space-opt")]
234249
#[test]
235250
fn space_option_01() {

0 commit comments

Comments
 (0)