From 56ce10347e29544a1d0ef2ae70ca6acb4d81a573 Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Sun, 21 Aug 2022 18:12:13 +0800 Subject: [PATCH] let `to nuon` convert column names with spaces (#6376) * let `to nuon` convert column names with spaces * change test --- crates/nu-command/src/formats/to/nuon.rs | 4 ++++ crates/nu-command/tests/format_conversions/nuon.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/nu-command/src/formats/to/nuon.rs b/crates/nu-command/src/formats/to/nuon.rs index 7717732178..7d0cf5bc25 100644 --- a/crates/nu-command/src/formats/to/nuon.rs +++ b/crates/nu-command/src/formats/to/nuon.rs @@ -102,6 +102,10 @@ fn value_to_string(v: &Value, span: Span) -> Result { let headers = get_columns(vals); if !headers.is_empty() && vals.iter().all(|x| x.columns() == headers) { // Table output + let headers: Vec = headers + .iter() + .map(|string| format!("\"{}\"", string)) + .collect(); let headers_output = headers.join(", "); let mut table_output = vec![]; diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index eac8d3d04a..d987513231 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -238,3 +238,14 @@ fn float_nan_parsed_properly() { assert_eq!(actual.out, "NaN") } + +#[test] +fn to_nuon_converts_columns_with_spaces() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + let test = [[a, b, "c d"]; [1 2 3] [4 5 6]]; $test | to nuon | from nuon + "# + )); + assert!(actual.err.is_empty()); +}