From 35a521d76238cfce4e856b102461bf5213ab63ac Mon Sep 17 00:00:00 2001 From: Kangaxx-0 <85712372+Kangaxx-0@users.noreply.github.com> Date: Fri, 16 Sep 2022 00:27:12 -0700 Subject: [PATCH] Fix 6529 - Trim overlay name (#6555) * trim overlay name * format * Update tests/overlays/mod.rs Co-authored-by: Stefan Holderbach * cleanup * new tests Co-authored-by: Stefan Holderbach --- .../src/core_commands/overlay/use_.rs | 4 +- tests/overlays/mod.rs | 62 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/core_commands/overlay/use_.rs b/crates/nu-command/src/core_commands/overlay/use_.rs index 052cdb7a9..e21fb843e 100644 --- a/crates/nu-command/src/core_commands/overlay/use_.rs +++ b/crates/nu-command/src/core_commands/overlay/use_.rs @@ -1,4 +1,5 @@ use nu_engine::{eval_block, find_in_dirs_env, redirect_env, CallExt}; +use nu_parser::trim_quotes_str; use nu_protocol::ast::{Call, Expr}; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ @@ -55,7 +56,8 @@ impl Command for OverlayUse { call: &Call, input: PipelineData, ) -> Result { - let name_arg: Spanned = call.req(engine_state, caller_stack, 0)?; + let mut name_arg: Spanned = call.req(engine_state, caller_stack, 0)?; + name_arg.item = trim_quotes_str(&name_arg.item).to_string(); let origin_module_id = if let Some(overlay_expr) = call.positional_nth(0) { if let Expr::Overlay(module_id) = overlay_expr.expr { diff --git a/tests/overlays/mod.rs b/tests/overlays/mod.rs index 57cca589d..b7267e985 100644 --- a/tests/overlays/mod.rs +++ b/tests/overlays/mod.rs @@ -993,3 +993,65 @@ fn overlay_preserve_hidden_alias() { assert_eq!(actual.out, "foo"); assert_eq!(actual_repl.out, "foo"); } + +#[test] +fn overlay_trim_single_quote() { + let inp = &[ + r#"module spam { export def foo [] { "foo" } }"#, + r#"overlay use 'spam'"#, + r#"overlay list | last "#, + ]; + + let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; "))); + + assert_eq!(actual.out, "spam"); +} + +#[test] +fn overlay_trim_single_quote_hide() { + let inp = &[ + r#"module spam { export def foo [] { "foo" } }"#, + r#"overlay use 'spam'"#, + r#"overlay hide spam "#, + r#"foo"#, + ]; + let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; "))); + let actual_repl = nu!(cwd: "tests/overlays", nu_repl_code(inp)); + + assert!(!actual.err.is_empty()); + #[cfg(windows)] + assert!(actual_repl.out != "foo"); + #[cfg(not(windows))] + assert!(!actual_repl.err.is_empty()); +} + +#[test] +fn overlay_trim_double_quote() { + let inp = &[ + r#"module spam { export def foo [] { "foo" } }"#, + r#"overlay use "spam" "#, + r#"overlay list | last "#, + ]; + + let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; "))); + + assert_eq!(actual.out, "spam"); +} + +#[test] +fn overlay_trim_double_quote_hide() { + let inp = &[ + r#"module spam { export def foo [] { "foo" } }"#, + r#"overlay use "spam" "#, + r#"overlay hide spam "#, + r#"foo"#, + ]; + let actual = nu!(cwd: "tests/overlays", pipeline(&inp.join("; "))); + let actual_repl = nu!(cwd: "tests/overlays", nu_repl_code(inp)); + + assert!(!actual.err.is_empty()); + #[cfg(windows)] + assert!(actual_repl.out != "foo"); + #[cfg(not(windows))] + assert!(!actual_repl.err.is_empty()); +}