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 ed3ca303..4155e97e 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -231,6 +231,19 @@ 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 document = input.parse::().unwrap(); + let actual = document.to_string(); + assert_eq(input, actual); +} + #[test] fn fruit() { let table = r#"