From 2a42c645d0bd2993fce0e57df40f89c5e884fd88 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 8 Mar 2023 12:00:01 -0600 Subject: [PATCH 1/2] test(edit): Add reproduction for 527 --- crates/toml_edit/tests/testsuite/parse.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index ed3ca303..69cbc116 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -231,6 +231,23 @@ fn empty_table() { table["foo"].as_table().unwrap(); } +#[test] +fn mixed_table_issue_527() { + let input = r#" +[package] +metadata.msrv = "1.65.0" + +[package.metadata.release.pre-release-replacements] +"#; + let expected = r#" +[package] +metadata.msrv = "1.65.0" +"#; + let document = input.parse::().unwrap(); + let actual = document.to_string(); + assert_eq(expected, actual); +} + #[test] fn fruit() { let table = r#" From 1c0df12c0df611361277ef59dca33e5d99b7cc67 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 8 Mar 2023 12:00:32 -0600 Subject: [PATCH 2/2] fix(edit): Ensure all is written Fixes #527 --- crates/toml_edit/src/encode.rs | 6 ++++-- crates/toml_edit/tests/testsuite/parse.rs | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs index 4747bd52..ea24c2db 100644 --- a/crates/toml_edit/src/encode.rs +++ b/crates/toml_edit/src/encode.rs @@ -237,11 +237,13 @@ fn visit_nested_tables<'t, F>( where F: FnMut(&'t Table, &Vec<&'t Key>, bool) -> Result, { - callback(table, path, is_array_of_tables)?; + if !table.is_dotted() { + callback(table, path, is_array_of_tables)?; + } for kv in table.items.values() { match kv.value { - Item::Table(ref t) if !t.is_dotted() => { + Item::Table(ref t) => { path.push(&kv.key); visit_nested_tables(t, path, false, callback)?; path.pop(); diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index 69cbc116..4155e97e 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -238,14 +238,10 @@ fn mixed_table_issue_527() { metadata.msrv = "1.65.0" [package.metadata.release.pre-release-replacements] -"#; - let expected = r#" -[package] -metadata.msrv = "1.65.0" "#; let document = input.parse::().unwrap(); let actual = document.to_string(); - assert_eq(expected, actual); + assert_eq(input, actual); } #[test]