Permalink
Browse files

Treat empty environment variables as unset

  • Loading branch information...
philbooth committed Sep 26, 2018
1 parent 4475925 commit a1cd868c0224f16d921a25f04cbc39cb03a5471d
Showing with 18 additions and 0 deletions.
  1. +1 −0 Cargo.toml
  2. +5 −0 src/env.rs
  3. +12 −0 tests/env.rs
@@ -19,6 +19,7 @@ json = ["serde_json"]
yaml = ["yaml-rust"]
hjson = ["serde-hjson"]
ini = ["rust-ini"]
ignore-empty-env-vars = []

[dependencies]
lazy_static = "1.0"
@@ -74,6 +74,11 @@ impl Source for Environment {
};

for (key, value) in env::vars() {
// Treat empty environment variables as unset
if cfg!(feature = "ignore-empty-env-vars") && value == "" {
continue;
}

let mut key = key.to_string();

// Check for prefix
@@ -60,3 +60,15 @@ fn test_separator_behavior() {

env::remove_var("C_B_A");
}

#[test]
#[cfg(feature = "ignore-empty-env-vars")]
fn test_empty_value_is_ignored() {
env::set_var("C_A_B", "");

let environment = Environment::new();

assert!(!environment.collect().unwrap().contains_key("c_a_b"));

env::remove_var("C_A_B");
}

0 comments on commit a1cd868

Please sign in to comment.