From ee4af92977fe1c3e9ca57d477016e16ce0e2366a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 2 Jan 2023 21:18:26 -0600 Subject: [PATCH] fix(parser): Detect more duplicate tables --- crates/toml_edit/src/parser/state.rs | 7 +++++++ crates/toml_edit/tests/decoder_compliance.rs | 7 +------ .../invalid/table/append-with-dotted-keys-1.stderr | 2 +- .../invalid/table/append-with-dotted-keys-2.stderr | 5 +++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/toml_edit/src/parser/state.rs b/crates/toml_edit/src/parser/state.rs index def0e151..2a286456 100644 --- a/crates/toml_edit/src/parser/state.rs +++ b/crates/toml_edit/src/parser/state.rs @@ -202,6 +202,13 @@ impl ParseState { table = last_child; } Item::Table(ref mut sweet_child_of_mine) => { + // "Likewise, using dotted keys to redefine tables already defined in [table] form is not allowed" + if dotted && !sweet_child_of_mine.is_implicit() { + return Err(CustomError::DuplicateKey { + key: key.get().into(), + table: None, + }); + } table = sweet_child_of_mine; } _ => unreachable!(), diff --git a/crates/toml_edit/tests/decoder_compliance.rs b/crates/toml_edit/tests/decoder_compliance.rs index 8d0f4f54..d33b53a4 100644 --- a/crates/toml_edit/tests/decoder_compliance.rs +++ b/crates/toml_edit/tests/decoder_compliance.rs @@ -3,11 +3,6 @@ mod decoder; fn main() { let decoder = decoder::Decoder; let mut harness = toml_test_harness::DecoderHarness::new(decoder); - harness - .ignore([ - "invalid/control/comment-cr.toml", - "invalid/table/append-with-dotted-keys-2.toml", - ]) - .unwrap(); + harness.ignore(["invalid/control/comment-cr.toml"]).unwrap(); harness.test(); } diff --git a/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-1.stderr b/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-1.stderr index 643f941f..0ccb245a 100644 --- a/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-1.stderr +++ b/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-1.stderr @@ -2,4 +2,4 @@ TOML parse error at line 17, column 3 | 17 | b.c.t = "Using dotted keys to add to [a.b.c] after explicitly defining it above is not allowed" | ^ -Duplicate key `t` +Duplicate key `c` diff --git a/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-2.stderr b/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-2.stderr index e69de29b..358930b2 100644 --- a/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-2.stderr +++ b/crates/toml_edit/tests/fixtures/invalid/table/append-with-dotted-keys-2.stderr @@ -0,0 +1,5 @@ +TOML parse error at line 8, column 3 + | +8 | b.c.d.k.t = "Using dotted keys to add to [a.b.c.d] after explicitly defining it above is not allowed" + | ^ +Duplicate key `d`