From 01583791f785e2883dc19b92c8c97b5fd31af0b6 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Tue, 13 Jun 2017 19:02:33 -0700 Subject: Ensure config keys are case insensitive --- src/file/format/json.rs | 2 +- src/file/format/toml.rs | 2 +- src/file/format/yaml.rs | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/file') diff --git a/src/file/format/json.rs b/src/file/format/json.rs index a3d80a7..4a94943 100644 --- a/src/file/format/json.rs +++ b/src/file/format/json.rs @@ -54,7 +54,7 @@ fn from_json_value(uri: Option<&String>, value: &serde_json::Value) -> Value { let mut m = HashMap::new(); for (key, value) in table { - m.insert(key.clone(), from_json_value(uri, value)); + m.insert(key.to_lowercase().clone(), from_json_value(uri, value)); } Value::new(uri, ValueKind::Table(m)) diff --git a/src/file/format/toml.rs b/src/file/format/toml.rs index f4a4196..633f39e 100644 --- a/src/file/format/toml.rs +++ b/src/file/format/toml.rs @@ -45,7 +45,7 @@ fn from_toml_value(uri: Option<&String>, value: &toml::Value) -> Value { let mut m = HashMap::new(); for (key, value) in table { - m.insert(key.clone(), from_toml_value(uri, value)); + m.insert(key.to_lowercase().clone(), from_toml_value(uri, value)); } Value::new(uri, m) diff --git a/src/file/format/yaml.rs b/src/file/format/yaml.rs index 2840438..7c3dd71 100644 --- a/src/file/format/yaml.rs +++ b/src/file/format/yaml.rs @@ -54,7 +54,7 @@ fn from_yaml_value(uri: Option<&String>, value: &yaml::Yaml) -> Value { let mut m = HashMap::new(); for (key, value) in table { if let Some(k) = key.as_str() { - m.insert(k.to_owned(), from_yaml_value(uri, value)); + m.insert(k.to_lowercase().to_owned(), from_yaml_value(uri, value)); } // TODO: should we do anything for non-string keys? } @@ -69,7 +69,12 @@ fn from_yaml_value(uri: Option<&String>, value: &yaml::Yaml) -> Value { Value::new(uri, ValueKind::Array(l)) } - // TODO: how should we handle Null and BadValue? + + yaml::Yaml::Null => { + Value::new(uri, ValueKind::Nil) + } + + // TODO: how should we BadValue? _ => { unimplemented!(); } -- cgit v1.2.3