config-rs
config-rs copied to clipboard
fix: Add slash character for path.parse to support nested slash environment variables
This library cannot parse successfully if the environment variables contain a slash and have nested values. For example:
use config::Config;
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct ChildValue {
v: u8,
}
#[derive(Debug, Deserialize, PartialEq)]
struct SlashNested {
#[serde(rename = "slash/nested")]
nested: ChildValue,
}
fn main() {
let env = config::Environment::with_prefix("APP").separator("_");
std::env::set_var("APP_slash/nested_v", "42");
let config = Config::builder().add_source(env).build().unwrap();
println!("{:?}", config.cache.to_string());
let app: SlashNested = config.try_deserialize().unwrap();
assert_eq!(
app,
SlashNested {
nested: ChildValue { v: 42 }
}
);
std::env::remove_var("APP_slash/nested_v");
}
Expected behavior:
- parse successfully with log
"{ slash/nested => { v => 42, }, }"
Current behavior:
- parse failed(panicked) with log
"{ slash/nested.v => 42, }"