summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/env.rs10
-rw-r--r--tests/env.rs11
2 files changed, 20 insertions, 1 deletions
diff --git a/src/env.rs b/src/env.rs
index 79472ba..5fc299d 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -76,8 +76,16 @@ impl Source for Environment {
_ => "",
};
+ let group_separator = match self.separator {
+ Some(ref separator) => separator,
+ _ => "_",
+ };
+
// Define a prefix pattern to test and exclude from keys
- let prefix_pattern = self.prefix.as_ref().map(|prefix| prefix.clone() + "_");
+ let prefix_pattern = self
+ .prefix
+ .as_ref()
+ .map(|prefix| format!("{}{}", prefix.clone(), group_separator));
for (key, value) in env::vars() {
// Treat empty environment variables as unset
diff --git a/tests/env.rs b/tests/env.rs
index bb1a1ec..ffc0572 100644
--- a/tests/env.rs
+++ b/tests/env.rs
@@ -71,3 +71,14 @@ fn test_empty_value_is_ignored() {
env::remove_var("C_A_B");
}
+
+#[test]
+fn test_custom_separator_behavior() {
+ env::set_var("C.B.A", "abc");
+
+ let environment = Environment::with_prefix("C").separator(".");
+
+ assert!(environment.collect().unwrap().contains_key("b.a"));
+
+ env::remove_var("C.B.A");
+}