From 30f4cc1fef70391920ed2232c9125f5f0c81eecc Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 13 Jun 2023 07:30:30 -0500 Subject: [PATCH] allow empty string arguments (#9420) # Description I'm not sure if this is a good idea or now but I did it to fix #9418. It allows you to pass empty string arguments like this. file named foo.nu ``` def main [--arg: string = dog] { if ($arg | is-empty) { echo "empty string" } else { echo $arg } } ``` `> nu foo.nu --arg ""` or `> nu foo.nu --arg=""` this gives an error `> nu foo.nu --arg` this returns the default argument `> nu foo.nu` closes #9418 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-parser/src/deparse.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/nu-parser/src/deparse.rs b/crates/nu-parser/src/deparse.rs index 98404490ad..e18da10ad8 100644 --- a/crates/nu-parser/src/deparse.rs +++ b/crates/nu-parser/src/deparse.rs @@ -26,6 +26,9 @@ pub fn escape_for_script_arg(input: &str) -> String { format!("`{arg_val}`") } else if arg_val.contains('"') || arg_val.contains('\\') { escape_quote_string(arg_val) + } else if arg_val.is_empty() { + // return an empty string + "''".to_string() } else { arg_val.into() }; @@ -37,6 +40,9 @@ pub fn escape_for_script_arg(input: &str) -> String { format!("`{input}`") } else if input.contains('"') || input.contains('\\') { escape_quote_string(input) + } else if input.is_empty() { + // return an empty string + "''".to_string() } else { input.to_string() }