diff --git a/Cargo.toml b/Cargo.toml index daa0570..0c71b83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust-ini" -version = "0.15.0" +version = "0.15.1" authors = ["Y. T. Chung "] description = "An Ini configuration file parsing library in Rust" repository = "https://github.com/zonyitoo/rust-ini" diff --git a/src/ini.rs b/src/ini.rs index 8627124..2bd9868 100644 --- a/src/ini.rs +++ b/src/ini.rs @@ -290,7 +290,7 @@ impl<'a> SectionSetter<'a> { SectionSetter { ini, section_name } } - /// Set key-value pair in this section (all with the same name) + /// Set (replace) key-value pair in this section (all with the same name) pub fn set(&'a mut self, key: K, value: V) -> &'a mut SectionSetter<'a> where K: Into, V: Into @@ -358,15 +358,15 @@ impl Properties { where K: Into, V: Into { - self.data.append(property_insert_key!(k.into()), v.into()); + self.data.insert(property_insert_key!(k.into()), v.into()); } - /// Replace key with (key, value) pair - pub fn replace(&mut self, k: K, v: V) + /// Append key with (key, value) pair + pub fn append(&mut self, k: K, v: V) where K: Into, V: Into { - self.data.insert(property_insert_key!(k.into()), v.into()); + self.data.append(property_insert_key!(k.into()), v.into()); } /// Get the first value associate with the key @@ -1031,7 +1031,7 @@ impl<'a> Parser<'a> { } SectionEntry::Occupied(mut o) => { // Insert into the last (current) section - o.last_mut().insert(curkey, mval); + o.last_mut().append(curkey, mval); } } curkey = "".into(); @@ -1176,8 +1176,8 @@ mod test { #[test] fn property_get_vec() { let mut props = Properties::new(); - props.insert("k1", "v1"); - props.insert("k1", "v2"); + props.append("k1", "v1"); + props.append("k1", "v2"); let res = props.get_all("k1").collect::>(); assert_eq!(res, vec!["v1", "v2"]); @@ -1189,8 +1189,8 @@ mod test { #[test] fn property_remove() { let mut props = Properties::new(); - props.insert("k1", "v1"); - props.insert("k1", "v2"); + props.append("k1", "v1"); + props.append("k1", "v2"); let res = props.remove_all("k1").collect::>(); assert_eq!(res, vec!["v1", "v2"]); @@ -1686,4 +1686,27 @@ bar = f assert_eq!(Some("e"), p3.get("foo")); assert_eq!(Some("f"), p3.get("bar")); } + + #[test] + fn fix_issue63() { + let section = "PHP"; + let key = "engine"; + let value = "On"; + let new_value = "Off"; + + // create a new configuration + let mut conf = Ini::new(); + conf.with_section(Some(section)).set(key, value); + + // assert the value is the one expected + let v = conf.get_from(Some(section), key).unwrap(); + assert_eq!(v, value); + + // update the section/key with a new value + conf.set_to(Some(section), key.to_string(), new_value.to_string()); + + // assert the new value was set + let v = conf.get_from(Some(section), key).unwrap(); + assert_eq!(v, new_value); + } }