error if command doesn't start with whitespace

main
EdenQwQ 2 years ago
parent a7529c49f2
commit 2b81e33446

@ -134,10 +134,15 @@ fn parse_contents(contents: String) -> Result<Vec<Hotkey>, Error> {
return Err(Error::InvalidConfig(ParseError::MissingCommand(real_line_no)));
}
let command = lines[i + 1].trim();
let command = lines[i + 1];
// Error if the command doesn't start with whitespace
if !command.starts_with(' ') && !command.starts_with('\t') {
return Err(Error::InvalidConfig(ParseError::CommandWithoutWhitespace(real_line_no)));
}
// Push a new hotkey to the hotkeys vector
hotkeys.push(Hotkey::new(key_presses, String::from(command)));
hotkeys.push(Hotkey::new(key_presses, String::from(command.trim())));
// Skip trying to parse the next line (command)
// because we already dealt with it
@ -388,7 +393,9 @@ pesto
#[test]
fn test_command_without_whitespace() -> std::io::Result<()> {
let contents = "0
let contents = "
0
firefox
1
@ -396,6 +403,8 @@ brave
";
let result = parse_contents(contents.to_string());
assert!(result.is_err());
let config_error = match result {
Ok(_) => panic!(
" Commands without whitespaces at the start are invalid.

Loading…
Cancel
Save