mirror of
https://github.com/nushell/nushell
synced 2025-01-12 13:19:01 +00:00
Disallow empty record with empty key,value pairs on ini format (#9722)
# Description This PR fixes #9556. Now, only a section will be added if it contains a key, value pair. With this change, `{record with 0 fields}`, should not appear anymore. For more context on empty sections, see issue on the [crate](https://github.com/zonyitoo/rust-ini/issues/109) ``` open -r whatever | from ini ╭─────────────┬──────────────────────────────────────────────────────────────╮ │ │ ╭───────────────────────┬──────────────────────────────────╮ │ │ placeholder │ │ aws_access_key_id │ AAAAAAAAAAAAAAAAAAAAA │ │ │ │ │ aws_secret_access_key │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │ │ │ │ ╰───────────────────────┴──────────────────────────────────╯ │ │ │ ╭───────────────────────┬──────────────────────────╮ │ │ default │ │ aws_access_key_id │ AAAAAAAAAAAAAAAAAA │ │ │ │ │ aws_secret_access_key │ AAAAAAAAAAAAAAAAAAAAAAA │ │ │ │ │ aws_session_token │ BBBBBBBBBBBBBBBBBBBBBBBB │ │ │ │ │ region │ us-east-1 │ │ │ │ │ output │ json │ │ │ │ ╰───────────────────────┴──────────────────────────╯ │ ╰─────────────┴──────────────────────────────────────────────────────────────╯ ``` # Tests + Formatting Now test for exact `from ini` output --------- Co-authored-by: sholderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
parent
36030cab8a
commit
1ba2269aa9
2 changed files with 17 additions and 8 deletions
|
@ -24,7 +24,10 @@ pub fn from_ini_call(call: &EvaluatedCall, input: &Value) -> Result<Value, Label
|
||||||
sections.push(section_name.to_owned());
|
sections.push(section_name.to_owned());
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
sections.push(String::new());
|
// Section (None) allows for key value pairs without a section
|
||||||
|
if !properties.is_empty() {
|
||||||
|
sections.push(String::new());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +41,14 @@ pub fn from_ini_call(call: &EvaluatedCall, input: &Value) -> Result<Value, Label
|
||||||
}
|
}
|
||||||
|
|
||||||
// section with its key value pairs
|
// section with its key value pairs
|
||||||
sections_key_value_pairs.push(Value::Record {
|
// Only add section if contains key,value pair
|
||||||
cols: keys_for_section,
|
if !properties.is_empty() {
|
||||||
vals: values_for_section,
|
sections_key_value_pairs.push(Value::Record {
|
||||||
span,
|
cols: keys_for_section,
|
||||||
});
|
vals: values_for_section,
|
||||||
|
span,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// all sections with all its key value pairs
|
// all sections with all its key value pairs
|
||||||
|
|
|
@ -10,10 +10,13 @@ fn parses_ini() {
|
||||||
let actual = nu_with_plugins!(
|
let actual = nu_with_plugins!(
|
||||||
cwd: TEST_CWD,
|
cwd: TEST_CWD,
|
||||||
plugin: ("nu_plugin_formats"),
|
plugin: ("nu_plugin_formats"),
|
||||||
"open sample.ini | get SectionOne.integer"
|
"open sample.ini | to nuon -r"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "1234")
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
r#"{SectionOne: {key: value, integer: "1234", real: "3.14", "string1": "Case 1", "string2": "Case 2"}, SectionTwo: {key: "new value", integer: "5678", real: "3.14", "string1": "Case 1", "string2": "Case 2", "string3": "Case 3"}}"#
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue