Skip to content

Conversation

nooop3
Copy link

@nooop3 nooop3 commented Apr 17, 2025

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, }"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant