Skip to content

fix: Add slash character for path.parse to support nested slash environment variables #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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