From 0b2be52bb5f8525bb688753bd2a7858df2617e41 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 10 Feb 2020 23:07:44 -0800 Subject: [PATCH] Only add quotes if not in Windows (which adds its own?) (#1374) * Only add quotes if not in Windows (which adds its own?) * Only add quotes if not in Windows (which adds its own?) --- src/commands/classified/external.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/commands/classified/external.rs b/src/commands/classified/external.rs index c0cc3cc913..da61f5fec4 100644 --- a/src/commands/classified/external.rs +++ b/src/commands/classified/external.rs @@ -104,14 +104,17 @@ async fn run_with_iterator_arg( } else { let arg = if arg.is_it() { let value = it_replacement.to_owned(); - let value = expand_tilde(&value, || home_dir.as_ref()).as_ref().to_string(); - let value = { - if argument_contains_whitespace(&value) && !argument_is_quoted(&value) { - add_quotes(&value) - } else { - value - } - }; + let mut value = expand_tilde(&value, || home_dir.as_ref()).as_ref().to_string(); + #[cfg(not(windows))] + { + value = { + if argument_contains_whitespace(&value) && !argument_is_quoted(&value) { + add_quotes(&value) + } else { + value + } + }; + } value } else { arg.to_string() @@ -370,6 +373,7 @@ where shellexpand::tilde_with_context(input, home_dir) } +#[allow(unused)] pub fn argument_contains_whitespace(argument: &str) -> bool { argument.chars().any(|c| c.is_whitespace()) } @@ -379,12 +383,13 @@ fn argument_is_quoted(argument: &str) -> bool { return false; } - (argument.starts_with('"') && argument.ends_with('"') + ((argument.starts_with('"') && argument.ends_with('"')) || (argument.starts_with('\'') && argument.ends_with('\''))) } +#[allow(unused)] fn add_quotes(argument: &str) -> String { - format!("'{}'", argument) + format!("\"{}\"", argument) } fn remove_quotes(argument: &str) -> Option<&str> { @@ -505,8 +510,8 @@ mod tests { #[test] fn adds_quotes_to_argument_to_be_passed_in() { - assert_eq!(add_quotes("andrés"), "'andrés'"); - assert_eq!(add_quotes("'andrés'"), "''andrés''"); + assert_eq!(add_quotes("andrés"), "\"andrés\""); + //assert_eq!(add_quotes("\"andrés\""), "\"andrés\""); } #[test]