File tree Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Expand file tree Collapse file tree 2 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -153,10 +153,10 @@ impl Environment {
153
153
/// To switch the default type back to type Strings you need to provide the keys which should be [`Vec<String>`] using this function.
154
154
pub fn with_list_parse_key ( mut self , key : & str ) -> Self {
155
155
if self . list_parse_keys . is_none ( ) {
156
- self . list_parse_keys = Some ( vec ! [ key. into ( ) ] )
156
+ self . list_parse_keys = Some ( vec ! [ key. to_lowercase ( ) ] )
157
157
} else {
158
158
self . list_parse_keys = self . list_parse_keys . map ( |mut keys| {
159
- keys. push ( key. into ( ) ) ;
159
+ keys. push ( key. to_lowercase ( ) ) ;
160
160
keys
161
161
} ) ;
162
162
}
@@ -287,6 +287,9 @@ impl Source for Environment {
287
287
ValueKind :: Float ( parsed)
288
288
} else if let Some ( separator) = & self . list_separator {
289
289
if let Some ( keys) = & self . list_parse_keys {
290
+ #[ cfg( feature = "convert-case" ) ]
291
+ let key = key. to_lowercase ( ) ;
292
+
290
293
if keys. contains ( & key) {
291
294
let v: Vec < Value > = value
292
295
. split ( separator)
Original file line number Diff line number Diff line change @@ -463,6 +463,58 @@ fn test_parse_string_and_list() {
463
463
)
464
464
}
465
465
466
+ #[ test]
467
+ fn test_parse_string_and_list_ignore_list_parse_key_case ( ) {
468
+ // using a struct in an enum here to make serde use `deserialize_any`
469
+ #[ derive( Deserialize , Debug ) ]
470
+ #[ serde( tag = "tag" ) ]
471
+ enum TestStringEnum {
472
+ String ( TestString ) ,
473
+ }
474
+
475
+ #[ derive( Deserialize , Debug ) ]
476
+ struct TestString {
477
+ string_val : String ,
478
+ string_list : Vec < String > ,
479
+ }
480
+
481
+ temp_env:: with_vars (
482
+ vec ! [
483
+ ( "LIST_STRING_LIST" , Some ( "test,string" ) ) ,
484
+ ( "LIST_STRING_VAL" , Some ( "test,string" ) ) ,
485
+ ] ,
486
+ || {
487
+ let environment = Environment :: default ( )
488
+ . prefix ( "LIST" )
489
+ . list_separator ( "," )
490
+ . with_list_parse_key ( "STRING_LIST" )
491
+ . try_parsing ( true ) ;
492
+
493
+ let config = Config :: builder ( )
494
+ . set_default ( "tag" , "String" )
495
+ . unwrap ( )
496
+ . add_source ( environment)
497
+ . build ( )
498
+ . unwrap ( ) ;
499
+
500
+ let config: TestStringEnum = config. try_deserialize ( ) . unwrap ( ) ;
501
+
502
+ match config {
503
+ TestStringEnum :: String ( TestString {
504
+ string_val,
505
+ string_list,
506
+ } ) => {
507
+ assert_eq ! ( String :: from( "test,string" ) , string_val) ;
508
+ assert_eq ! (
509
+ vec![ String :: from( "test" ) , String :: from( "string" ) ] ,
510
+ string_list
511
+ ) ;
512
+ }
513
+ }
514
+ } ,
515
+ )
516
+ }
517
+
466
518
#[ test]
467
519
fn test_parse_nested_kebab ( ) {
468
520
use config:: Case ;
You can’t perform that action at this time.
0 commit comments