From 1ba2269aa9514bc9c0a4f0f60c176eddb5c3957e Mon Sep 17 00:00:00 2001 From: David Matos Date: Tue, 18 Jul 2023 22:14:18 +0200 Subject: [PATCH] Disallow empty record with empty key,value pairs on ini format (#9722) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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 --- crates/nu_plugin_formats/src/from/ini.rs | 18 ++++++++++++------ tests/plugins/formats/ini.rs | 7 +++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/nu_plugin_formats/src/from/ini.rs b/crates/nu_plugin_formats/src/from/ini.rs index 03c5a36ec0..3c09934f1f 100644 --- a/crates/nu_plugin_formats/src/from/ini.rs +++ b/crates/nu_plugin_formats/src/from/ini.rs @@ -24,7 +24,10 @@ pub fn from_ini_call(call: &EvaluatedCall, input: &Value) -> Result { - 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