Skip to content

Commit 51eacda

Browse files
committed
Revert "Make the parse list key to lowercase when insert the keys"
This reverts commit b3d8518.
1 parent 740d57d commit 51eacda

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/env.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ impl Environment {
155155
/// To switch the default type back to type Strings you need to provide the keys which should be [`Vec<String>`] using this function.
156156
pub fn with_list_parse_key(mut self, key: &str) -> Self {
157157
if self.list_parse_keys.is_none() {
158-
self.list_parse_keys = Some(vec![key.to_lowercase()]);
158+
self.list_parse_keys = Some(vec![key.into()]);
159159
} else {
160160
self.list_parse_keys = self.list_parse_keys.map(|mut keys| {
161-
keys.push(key.to_lowercase());
161+
keys.push(key.into());
162162
keys
163163
});
164164
}
@@ -289,9 +289,6 @@ impl Source for Environment {
289289
ValueKind::Float(parsed)
290290
} else if let Some(separator) = &self.list_separator {
291291
if let Some(keys) = &self.list_parse_keys {
292-
#[cfg(feature = "convert-case")]
293-
let key = key.to_lowercase();
294-
295292
if keys.contains(&key) {
296293
let v: Vec<Value> = value
297294
.split(separator)

tests/testsuite/env.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use config::{Config, Environment, Source};
21
use serde_derive::Deserialize;
2+
use snapbox::{assert_data_eq, str};
3+
4+
use config::{Config, Environment, Source};
35

46
/// Reminder that tests using env variables need to use different env variable names, since
57
/// tests can be run in parallel
@@ -474,11 +476,13 @@ fn test_parse_string_and_list_ignore_list_parse_key_case() {
474476
// using a struct in an enum here to make serde use `deserialize_any`
475477
#[derive(Deserialize, Debug)]
476478
#[serde(tag = "tag")]
479+
#[allow(dead_code)]
477480
enum TestStringEnum {
478481
String(TestString),
479482
}
480483

481484
#[derive(Deserialize, Debug)]
485+
#[allow(dead_code)]
482486
struct TestString {
483487
string_val: String,
484488
string_list: Vec<String>,
@@ -503,20 +507,13 @@ fn test_parse_string_and_list_ignore_list_parse_key_case() {
503507
.build()
504508
.unwrap();
505509

506-
let config: TestStringEnum = config.try_deserialize().unwrap();
510+
let res = config.try_deserialize::<TestStringEnum>();
507511

508-
match config {
509-
TestStringEnum::String(TestString {
510-
string_val,
511-
string_list,
512-
}) => {
513-
assert_eq!(String::from("test,string"), string_val);
514-
assert_eq!(
515-
vec![String::from("test"), String::from("string")],
516-
string_list
517-
);
518-
}
519-
}
512+
assert!(res.is_err());
513+
assert_data_eq!(
514+
res.unwrap_err().to_string(),
515+
str![[r#"invalid type: string "test,string", expected a sequence"#]]
516+
);
520517
},
521518
);
522519
}

0 commit comments

Comments
 (0)