Skip to content

Commit

Permalink
fix(edit): Ensure Key::from_str doesnt rely on Document
Browse files Browse the repository at this point in the history
Fixes #559
  • Loading branch information
epage committed May 23, 2023
1 parent 9339a08 commit c9b2192
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions crates/toml_edit/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ impl Key {
}

fn try_parse_simple(s: &str) -> Result<Key, crate::TomlError> {
parser::parse_key(s)
let mut key = parser::parse_key(s)?;
key.despan(s);
Ok(key)
}

fn try_parse_path(s: &str) -> Result<Vec<Key>, crate::TomlError> {
parser::parse_key_path(s)
let mut keys = parser::parse_key_path(s)?;
for key in &mut keys {
key.despan(s);
}
Ok(keys)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/toml_edit/tests/testsuite/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,5 +1486,5 @@ fn despan_keys() {
toml_edit::Item::Value(Value::Integer(toml_edit::Formatted::new(2))),
);

assert_eq!(doc.to_string(), "aaaaaa = 1\naaa = 2\n");
assert_eq!(doc.to_string(), "aaaaaa = 1\nbbb = 2\n");
}

0 comments on commit c9b2192

Please sign in to comment.