File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -76,8 +76,16 @@ impl Source for Environment {
76
76
_ => "" ,
77
77
} ;
78
78
79
+ let group_separator = match self . separator {
80
+ Some ( ref separator) => separator,
81
+ _ => "_" ,
82
+ } ;
83
+
79
84
// Define a prefix pattern to test and exclude from keys
80
- let prefix_pattern = self . prefix . as_ref ( ) . map ( |prefix| prefix. clone ( ) + "_" ) ;
85
+ let prefix_pattern = self
86
+ . prefix
87
+ . as_ref ( )
88
+ . map ( |prefix| format ! ( "{}{}" , prefix. clone( ) , group_separator) ) ;
81
89
82
90
for ( key, value) in env:: vars ( ) {
83
91
// Treat empty environment variables as unset
Original file line number Diff line number Diff line change @@ -71,3 +71,14 @@ fn test_empty_value_is_ignored() {
71
71
72
72
env:: remove_var ( "C_A_B" ) ;
73
73
}
74
+
75
+ #[ test]
76
+ fn test_custom_separator_behavior ( ) {
77
+ env:: set_var ( "C.B.A" , "abc" ) ;
78
+
79
+ let environment = Environment :: with_prefix ( "C" ) . separator ( "." ) ;
80
+
81
+ assert ! ( environment. collect( ) . unwrap( ) . contains_key( "b.a" ) ) ;
82
+
83
+ env:: remove_var ( "C.B.A" ) ;
84
+ }
You can’t perform that action at this time.
0 commit comments