mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Improve external quoting logic (#3579)
* Add tests and improve quoting logic * fmt * Fix clippy ling * Fix clippy ling
This commit is contained in:
@ -38,6 +38,21 @@ pub(crate) fn run_external_command(
|
||||
run_with_stdin(command, context, input, external_redirection)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn trim_double_quotes(input: &str) -> String {
|
||||
let mut chars = input.chars();
|
||||
|
||||
match (chars.next(), chars.next_back()) {
|
||||
(Some('"'), Some('"')) => chars.collect(),
|
||||
_ => input.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn escape_where_needed(input: &str) -> String {
|
||||
input.split(' ').join("\\ ").split('\'').join("\\'")
|
||||
}
|
||||
|
||||
fn run_with_stdin(
|
||||
command: ExternalCommand,
|
||||
context: &mut EvaluationContext,
|
||||
@ -81,6 +96,7 @@ fn run_with_stdin(
|
||||
}
|
||||
_ => {
|
||||
let trimmed_value_string = value.as_string()?.trim_end_matches('\n').to_string();
|
||||
//let trimmed_value_string = trim_quotes(&trimmed_value_string);
|
||||
command_args.push((trimmed_value_string, is_literal));
|
||||
}
|
||||
}
|
||||
@ -108,7 +124,12 @@ fn run_with_stdin(
|
||||
let escaped = escape_double_quotes(&arg);
|
||||
add_double_quotes(&escaped)
|
||||
} else {
|
||||
arg.as_ref().to_string()
|
||||
let trimmed = trim_double_quotes(&arg);
|
||||
if trimmed != arg {
|
||||
escape_where_needed(&trimmed)
|
||||
} else {
|
||||
trimmed
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
|
@ -25,6 +25,15 @@ pub fn cococo() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn meow() {
|
||||
let args: Vec<String> = args();
|
||||
|
||||
for arg in args.iter().skip(1) {
|
||||
let contents = std::fs::read_to_string(arg).expect("Expected a filepath");
|
||||
println!("{}", contents);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nonu() {
|
||||
args().iter().skip(1).for_each(|arg| print!("{}", arg));
|
||||
}
|
||||
|
Reference in New Issue
Block a user