Skip to content

Commit

Permalink
fix(parser): Error on duplicate table created as dotted
Browse files Browse the repository at this point in the history
Fixes #509
  • Loading branch information
epage committed Feb 6, 2023
1 parent e006c77 commit fc59238
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crates/toml_edit/src/parser/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ impl ParseState {

self.current_table_position += 1;
self.current_table.decor = decor;
self.current_table.set_implicit(false);
self.current_table.set_dotted(false);
self.current_table.set_position(self.current_table_position);
self.current_table.span = Some(span);
self.current_is_array = true;
Expand Down Expand Up @@ -152,6 +154,8 @@ impl ParseState {

self.current_table_position += 1;
self.current_table.decor = decor;
self.current_table.set_implicit(false);
self.current_table.set_dotted(false);
self.current_table.set_position(self.current_table_position);
self.current_table.span = Some(span);
self.current_is_array = false;
Expand Down
14 changes: 12 additions & 2 deletions crates/toml_edit/tests/testsuite/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ expected `]`

#[test]
fn duplicate_table_after_dotted_key_issue_509() {
"
let err = "
[dependencies.foo]
version = \"0.16\"
Expand All @@ -56,7 +56,17 @@ libc = \"0.2\"
rand = \"0.3.14\"
"
.parse::<toml_edit::Document>()
.unwrap();
.unwrap_err();
snapbox::assert_eq(
r#"TOML parse error at line 8, column 1
|
8 | [dependencies]
| ^
invalid table header
duplicate key `dependencies` in document root
"#,
err.to_string(),
);
}

#[test]
Expand Down

0 comments on commit fc59238

Please sign in to comment.