From d302d630304be9154b52058d4f6320f400bbdada Mon Sep 17 00:00:00 2001 From: "A. Taha Baki" Date: Mon, 7 Aug 2023 22:40:38 +0300 Subject: [PATCH] str-expand: update bracoxide to v0.1.2, fixes #9913 (#9940) Fixes: #9913 Changes: - updated crate bracoxide from v0.1.1 to v0.1.2 --- crates/nu-command/Cargo.toml | 2 +- crates/nu-command/src/strings/str_/expand.rs | 65 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index 6260649a9a..9cc78a57c4 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -93,7 +93,7 @@ url = "2.2" uuid = { version = "1.3", features = ["v4"] } wax = { version = "0.5" } which = { version = "4.4", optional = true } -bracoxide = "0.1.1" +bracoxide = "0.1.2" [target.'cfg(windows)'.dependencies] winreg = "0.50" diff --git a/crates/nu-command/src/strings/str_/expand.rs b/crates/nu-command/src/strings/str_/expand.rs index 24f6d33fba..08e4bbe1e8 100644 --- a/crates/nu-command/src/strings/str_/expand.rs +++ b/crates/nu-command/src/strings/str_/expand.rs @@ -65,6 +65,18 @@ impl Command for SubCommand { },) }, + Example { + description: "Commas that are not inside any braces need to be skipped.", + example: "'Welcome\\, {home,mon ami}!' | str expand", + result: Some(Value::List{ + vals: vec![ + Value::test_string("Welcome, home!"), + Value::test_string("Welcome, mon ami!"), + ], + span: Span::test_data() + },) + }, + Example { description: "Use double backslashes to add a backslash.", example: "'A{B\\\\,C}' | str expand", @@ -270,6 +282,59 @@ fn str_expand(contents: &str, span: Span, value_span: Span) -> Value { #[cfg(test)] mod tests { use super::*; + + #[test] + fn dots() { + assert_eq!( + str_expand("{a.b.c,d}", Span::test_data(), Span::test_data()), + Value::List { + vals: vec![ + Value::String { + val: String::from("a.b.c"), + span: Span::test_data(), + }, + Value::String { + val: String::from("d"), + span: Span::test_data(), + }, + ], + span: Span::test_data(), + } + ); + assert_eq!( + str_expand("{1.2.3,a}", Span::test_data(), Span::test_data()), + Value::List { + vals: vec![ + Value::String { + val: String::from("1.2.3"), + span: Span::test_data(), + }, + Value::String { + val: String::from("a"), + span: Span::test_data(), + }, + ], + span: Span::test_data(), + } + ); + assert_eq!( + str_expand("{a-1.2,b}", Span::test_data(), Span::test_data()), + Value::List { + vals: vec![ + Value::String { + val: String::from("a-1.2"), + span: Span::test_data(), + }, + Value::String { + val: String::from("b"), + span: Span::test_data(), + }, + ], + span: Span::test_data(), + } + ); + } + #[test] fn test_examples() { use crate::test_examples;