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 {
7676 _ => "" ,
7777 } ;
7878
79+ let group_separator = match self . separator {
80+ Some ( ref separator) => separator,
81+ _ => "_" ,
82+ } ;
83+
7984 // 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) ) ;
8189
8290 for ( key, value) in env:: vars ( ) {
8391 // 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() {
7171
7272 env:: remove_var ( "C_A_B" ) ;
7373}
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