Skip to content

Commit

Permalink
Merge pull request #510 from epage/dup
Browse files Browse the repository at this point in the history
fix(parser): Error on duplicate table created as dotted
  • Loading branch information
epage authored Feb 6, 2023
2 parents 41390b3 + fc59238 commit 36ca0b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 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
26 changes: 26 additions & 0 deletions crates/toml_edit/tests/testsuite/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ expected `]`
);
}

#[test]
fn duplicate_table_after_dotted_key_issue_509() {
let err = "
[dependencies.foo]
version = \"0.16\"
[dependencies]
libc = \"0.2\"
[dependencies]
rand = \"0.3.14\"
"
.parse::<toml_edit::Document>()
.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]
fn bad() {
let toml_input = "a = 01";
Expand Down

0 comments on commit 36ca0b9

Please sign in to comment.