diff --git a/crates/toml_edit/src/key.rs b/crates/toml_edit/src/key.rs index 203445a7..b7038c36 100644 --- a/crates/toml_edit/src/key.rs +++ b/crates/toml_edit/src/key.rs @@ -128,11 +128,17 @@ impl Key { } fn try_parse_simple(s: &str) -> Result { - parser::parse_key(s) + let mut key = parser::parse_key(s)?; + key.despan(s); + Ok(key) } fn try_parse_path(s: &str) -> Result, 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) } } diff --git a/crates/toml_edit/tests/testsuite/parse.rs b/crates/toml_edit/tests/testsuite/parse.rs index c9f6411e..f1c3c27c 100644 --- a/crates/toml_edit/tests/testsuite/parse.rs +++ b/crates/toml_edit/tests/testsuite/parse.rs @@ -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"); }