Skip to content

Commit

Permalink
Revert "Make the parse list key to lowercase when insert the keys"
Browse files Browse the repository at this point in the history
This reverts commit b3d8518.
  • Loading branch information
epage committed Dec 17, 2024
1 parent 740d57d commit 51eacda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>`] 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
});
}
Expand Down Expand Up @@ -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> = value
.split(separator)
Expand Down
25 changes: 11 additions & 14 deletions tests/testsuite/env.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<String>,
Expand All @@ -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::<TestStringEnum>();

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"#]]
);
},
);
}
Expand Down

0 comments on commit 51eacda

Please sign in to comment.