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:
David Matos
2023-07-18 22:14:18 +02:00
committed by GitHub
parent 36030cab8a
commit 1ba2269aa9
2 changed files with 17 additions and 8 deletions

View File

@ -24,7 +24,10 @@ pub fn from_ini_call(call: &EvaluatedCall, input: &Value) -> Result<Value, Label
sections.push(section_name.to_owned());
}
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
sections_key_value_pairs.push(Value::Record {
cols: keys_for_section,
vals: values_for_section,
span,
});
// Only add section if contains key,value pair
if !properties.is_empty() {
sections_key_value_pairs.push(Value::Record {
cols: keys_for_section,
vals: values_for_section,
span,
});
}
}
// all sections with all its key value pairs