forked from extern/nushell
Fix quoting of empty string in to nuon
(#7632)
Closes https://github.com/nushell/nushell/issues/7631
This commit is contained in:
parent
b543063749
commit
be31182969
@ -221,6 +221,9 @@ static NEEDS_QUOTES_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fn needs_quotes(string: &str) -> bool {
|
fn needs_quotes(string: &str) -> bool {
|
||||||
|
if string.is_empty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// These are case-sensitive keywords
|
// These are case-sensitive keywords
|
||||||
match string {
|
match string {
|
||||||
// `true`/`false`/`null` are active keywords in JSON and NUON
|
// `true`/`false`/`null` are active keywords in JSON and NUON
|
||||||
|
@ -296,6 +296,41 @@ fn to_nuon_converts_columns_with_spaces() {
|
|||||||
assert!(actual.err.is_empty());
|
assert!(actual.err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_quotes_empty_string() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
let test = ""; $test | to nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
assert!(actual.err.is_empty());
|
||||||
|
assert_eq!(actual.out, r#""""#)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_quotes_empty_string_in_list() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
let test = [""]; $test | to nuon | from nuon | $in == [""]
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
assert!(actual.err.is_empty());
|
||||||
|
assert_eq!(actual.out, "true")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_nuon_quotes_empty_string_in_table() {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
|
r#"
|
||||||
|
let test = [[a, b]; ['', la] [le lu]]; $test | to nuon | from nuon
|
||||||
|
"#
|
||||||
|
));
|
||||||
|
assert!(actual.err.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn does_not_quote_strings_unnecessarily() {
|
fn does_not_quote_strings_unnecessarily() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
@ -331,7 +366,7 @@ fn quotes_some_strings_necessarily() {
|
|||||||
'-11.0..<-15.0', '11.0..<-15.0', '-11.0..<15.0',
|
'-11.0..<-15.0', '11.0..<-15.0', '-11.0..<15.0',
|
||||||
'-11.0..', '11.0..', '..15.0', '..-15.0', '..<15.0', '..<-15.0',
|
'-11.0..', '11.0..', '..15.0', '..-15.0', '..<15.0', '..<-15.0',
|
||||||
'2000-01-01', '2022-02-02T14:30:00', '2022-02-02T14:30:00+05:00',
|
'2000-01-01', '2022-02-02T14:30:00', '2022-02-02T14:30:00+05:00',
|
||||||
',',
|
',',''
|
||||||
'&&'
|
'&&'
|
||||||
] | to nuon | from nuon | describe
|
] | to nuon | from nuon | describe
|
||||||
"#
|
"#
|
||||||
|
Loading…
Reference in New Issue
Block a user