From 51eacdaf84df8f51e6aadb756c24bbd6cccc8fe3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 17 Dec 2024 14:08:20 -0600 Subject: [PATCH] Revert "Make the parse list key to lowercase when insert the keys" This reverts commit b3d851878dd88a62c19cecf3e3bf8a8e2be5309a. --- src/env.rs | 7 ++----- tests/testsuite/env.rs | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/env.rs b/src/env.rs index 890f0997..2dad9235 100644 --- a/src/env.rs +++ b/src/env.rs @@ -155,10 +155,10 @@ impl Environment { /// To switch the default type back to type Strings you need to provide the keys which should be [`Vec`] using this function. pub fn with_list_parse_key(mut self, key: &str) -> Self { if self.list_parse_keys.is_none() { - self.list_parse_keys = Some(vec![key.to_lowercase()]); + self.list_parse_keys = Some(vec![key.into()]); } else { self.list_parse_keys = self.list_parse_keys.map(|mut keys| { - keys.push(key.to_lowercase()); + keys.push(key.into()); keys }); } @@ -289,9 +289,6 @@ impl Source for Environment { ValueKind::Float(parsed) } else if let Some(separator) = &self.list_separator { if let Some(keys) = &self.list_parse_keys { - #[cfg(feature = "convert-case")] - let key = key.to_lowercase(); - if keys.contains(&key) { let v: Vec = value .split(separator) diff --git a/tests/testsuite/env.rs b/tests/testsuite/env.rs index 4befa5bb..00a59e8e 100644 --- a/tests/testsuite/env.rs +++ b/tests/testsuite/env.rs @@ -1,5 +1,7 @@ -use config::{Config, Environment, Source}; use serde_derive::Deserialize; +use snapbox::{assert_data_eq, str}; + +use config::{Config, Environment, Source}; /// Reminder that tests using env variables need to use different env variable names, since /// tests can be run in parallel @@ -474,11 +476,13 @@ fn test_parse_string_and_list_ignore_list_parse_key_case() { // using a struct in an enum here to make serde use `deserialize_any` #[derive(Deserialize, Debug)] #[serde(tag = "tag")] + #[allow(dead_code)] enum TestStringEnum { String(TestString), } #[derive(Deserialize, Debug)] + #[allow(dead_code)] struct TestString { string_val: String, string_list: Vec, @@ -503,20 +507,13 @@ fn test_parse_string_and_list_ignore_list_parse_key_case() { .build() .unwrap(); - let config: TestStringEnum = config.try_deserialize().unwrap(); + let res = config.try_deserialize::(); - match config { - TestStringEnum::String(TestString { - string_val, - string_list, - }) => { - assert_eq!(String::from("test,string"), string_val); - assert_eq!( - vec![String::from("test"), String::from("string")], - string_list - ); - } - } + assert!(res.is_err()); + assert_data_eq!( + res.unwrap_err().to_string(), + str![[r#"invalid type: string "test,string", expected a sequence"#]] + ); }, ); }