Skip to content

Commit

Permalink
fix: Fix the application panicing when multiple modifier keys and no …
Browse files Browse the repository at this point in the history
…main key is set
  • Loading branch information
IAmJSD committed Aug 9, 2024
1 parent 86e68f7 commit ef99a47
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/hotkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,16 @@ fn parse_hotkey(hotkey: &str) -> Result<HotKey, HotKeyParseError> {
}
}

Ok(HotKey::new(Some(mods), key.unwrap()))
Ok(HotKey::new(
Some(mods),
match key {
Some(k) => k,
None => {
// This would mean the hotkey is more than one modifier with no key.
return Err(HotKeyParseError::InvalidFormat(hotkey.to_string()));
}
},
))
}

fn parse_key(key: &str) -> Result<Code, HotKeyParseError> {
Expand Down Expand Up @@ -448,6 +457,12 @@ fn test_parse_hotkey() {
id: 0,
}
);

// Ensure that if it is just multiple modifiers, we do not panic.
// This would be a regression if this happened.
if let Ok(_) = HotKey::from_str("Shift+Ctrl") {
panic!("This is not a valid hotkey");
}
}

#[test]
Expand Down

0 comments on commit ef99a47

Please sign in to comment.