Skip to content

Commit 5529e3f

Browse files
committed
Ensure empty sections are parsed but empty
1 parent 8cb1c1a commit 5529e3f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/ini.rs

+2
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ impl Ini {
761761
(Some(0), Some(end)) => {
762762
section = caser(trimmed[1..end].trim());
763763

764+
map.entry(section.clone()).or_default();
765+
764766
continue;
765767
}
766768
(Some(0), None) => {

tests/test.rs

+19
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,25 @@ fn cs() -> Result<(), Box<dyn Error>> {
231231
Ok(())
232232
}
233233

234+
#[test]
235+
fn ensure_empty_sections_exist() -> Result<(), Box<dyn Error>> {
236+
const FILE_CONTENTS: &str = "
237+
[basic_section]
238+
basic_option=basic_value
239+
[empty_section]
240+
";
241+
242+
let mut config = Ini::new();
243+
config.read(FILE_CONTENTS.to_owned())?;
244+
245+
assert_eq!(
246+
config.sections(),
247+
vec![String::from("basic_section"), String::from("empty_section")]
248+
);
249+
250+
Ok(())
251+
}
252+
234253
#[test]
235254
#[cfg(feature = "indexmap")]
236255
fn sort_on_write() -> Result<(), Box<dyn Error>> {

0 commit comments

Comments
 (0)