diff --git a/crates/nu-std/std/formats/mod.nu b/crates/nu-std/std/formats/mod.nu index addfa4c1c9..a0484e42f4 100644 --- a/crates/nu-std/std/formats/mod.nu +++ b/crates/nu-std/std/formats/mod.nu @@ -36,5 +36,5 @@ export def "from ndnuon" []: [string -> any] { # Convert structured data to NDNUON, i.e. newline-delimited NUON export def "to ndnuon" []: [any -> string] { - each { to nuon --raw } | to text + each { to nuon --raw | str replace --all "\n" '\n' } | to text } diff --git a/crates/nu-std/tests/test_formats.nu b/crates/nu-std/tests/test_formats.nu index ec1f6adb47..44a89eeaad 100644 --- a/crates/nu-std/tests/test_formats.nu +++ b/crates/nu-std/tests/test_formats.nu @@ -128,3 +128,17 @@ def to_ndnuon_single_object [] { let expect = "{a: 1}" assert equal $result $expect "could not convert to NDNUON" } + +#[test] +def to_ndnuon_multiline_strings [] { + let result = "foo\n\\n\nbar" | to ndnuon + let expect = '"foo\n\\n\nbar"' + assert equal $result $expect "could not convert multiline string to NDNUON" +} + +#[test] +def from_ndnuon_multiline_strings [] { + let result = '"foo\n\\n\nbar"' | from ndnuon + let expect = ["foo\n\\n\nbar"] + assert equal $result $expect "could not convert multiline string from NDNUON" +} diff --git a/crates/nu-std/tests/test_std_formats.nu b/crates/nu-std/tests/test_std_formats.nu index ed6b079d7e..1ca7516c20 100644 --- a/crates/nu-std/tests/test_std_formats.nu +++ b/crates/nu-std/tests/test_std_formats.nu @@ -128,3 +128,17 @@ def to_ndnuon_single_object [] { let expect = "{a: 1}" assert equal $result $expect "could not convert to NDNUON" } + +#[test] +def to_ndnuon_multiline_strings [] { + let result = "foo\n\\n\nbar" | formats to ndnuon + let expect = '"foo\n\\n\nbar"' + assert equal $result $expect "could not convert multiline string to NDNUON" +} + +#[test] +def from_ndnuon_multiline_strings [] { + let result = '"foo\n\\n\nbar"' | formats from ndnuon + let expect = ["foo\n\\n\nbar"] + assert equal $result $expect "could not convert multiline string from NDNUON" +}