Skip to content

Commit fc59238

Browse files
committed
fix(parser): Error on duplicate table created as dotted
Fixes #509
1 parent e006c77 commit fc59238

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

crates/toml_edit/src/parser/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ impl ParseState {
117117

118118
self.current_table_position += 1;
119119
self.current_table.decor = decor;
120+
self.current_table.set_implicit(false);
121+
self.current_table.set_dotted(false);
120122
self.current_table.set_position(self.current_table_position);
121123
self.current_table.span = Some(span);
122124
self.current_is_array = true;
@@ -152,6 +154,8 @@ impl ParseState {
152154

153155
self.current_table_position += 1;
154156
self.current_table.decor = decor;
157+
self.current_table.set_implicit(false);
158+
self.current_table.set_dotted(false);
155159
self.current_table.set_position(self.current_table_position);
156160
self.current_table.span = Some(span);
157161
self.current_is_array = false;

crates/toml_edit/tests/testsuite/invalid.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ expected `]`
4545

4646
#[test]
4747
fn duplicate_table_after_dotted_key_issue_509() {
48-
"
48+
let err = "
4949
[dependencies.foo]
5050
version = \"0.16\"
5151
@@ -56,7 +56,17 @@ libc = \"0.2\"
5656
rand = \"0.3.14\"
5757
"
5858
.parse::<toml_edit::Document>()
59-
.unwrap();
59+
.unwrap_err();
60+
snapbox::assert_eq(
61+
r#"TOML parse error at line 8, column 1
62+
|
63+
8 | [dependencies]
64+
| ^
65+
invalid table header
66+
duplicate key `dependencies` in document root
67+
"#,
68+
err.to_string(),
69+
);
6070
}
6171

6272
#[test]

0 commit comments

Comments
 (0)