diff --git a/Cargo.lock b/Cargo.lock index a6f90dcd..3bf7a28c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1932,9 +1932,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b46c9238346fec3169f99251eda26e918ab71cdf382a660e46076ff1b1b16729" +checksum = "8c29c21e11af3c58476a1063cb550e255c45c60928bf7f272462a533e7a2b406" dependencies = [ "combine", "indexmap", diff --git a/Cargo.toml b/Cargo.toml index 39340751..f2fca67d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ shadow-rs = "0.7.2" versions = "3.0.3" strsim = "0.10.0" sha-1 = "0.9.8" -toml_edit = "0.6.0" +toml_edit = "0.8.0" process_control = { version = "3.1.0", features = ["crossbeam-channel"] } diff --git a/src/configure.rs b/src/configure.rs index dca7565f..c77cc56e 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -32,9 +32,17 @@ pub fn update_configuration(name: &str, value: &str) { } fn handle_update_configuration(doc: &mut Document, name: &str, value: &str) -> Result<(), String> { - let mut current_item = &mut doc.root; + let mut keys = name.split('.'); - for key in name.split('.') { + let first_key = keys.next().unwrap_or_default(); + if first_key.is_empty() { + return Err("Empty table keys are not supported".to_owned()); + } + + let table = doc.as_table_mut(); + let mut current_item = table.entry(first_key).or_insert_with(toml_edit::table); + + for key in keys { if !current_item.is_table_like() { return Err("This command can only index into TOML tables".to_owned()); } @@ -429,6 +437,7 @@ mod tests { assert!(handle_update_configuration(&mut doc, ".....", "true").is_err()); assert!(handle_update_configuration(&mut doc, "a.a.a..a.a", "true").is_err()); assert!(handle_update_configuration(&mut doc, "a.a.a.a.a.", "true").is_err()); + assert!(handle_update_configuration(&mut doc, ".a.a.a.a.a", "true").is_err()); } #[test]