From 41dc5da4c9b0b407a304406e355a4e58043d47ec Mon Sep 17 00:00:00 2001 From: Enzo Souza Duarte Date: Mon, 23 Nov 2026 23:36:36 -0300 Subject: [PATCH] Config: ignore an empty VICTORY_CONFIG (cherry picked from commit fd44561ea1180aff5380285527fb8cac8195f4e8) --- crates/victory-core/src/config.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/victory-core/src/config.rs b/crates/victory-core/src/config.rs index b65014e..eb2d85e 100644 --- a/crates/victory-core/src/config.rs +++ b/crates/victory-core/src/config.rs @@ -46,7 +46,7 @@ struct FilePaths { impl Config { /// Loads configuration from the environment and the config file. pub fn load() -> Result { - let explicit = std::env::var_os("VICTORY_CONFIG").map(PathBuf::from); + let explicit = explicit_config_path(|k| std::env::var_os(k)); let path = explicit .clone() .unwrap_or_else(|| PathBuf::from("victory.toml")); @@ -119,6 +119,14 @@ impl Config { } } +/// The config file explicitly named by the environment, if any. An empty +/// `VICTORY_CONFIG` means unset, like the other path variables. +fn explicit_config_path(env: impl Fn(&str) -> Option) -> Option { + env("VICTORY_CONFIG") + .filter(|v| !v.is_empty()) + .map(PathBuf::from) +} + fn subdir(root: &Path, sub: &str) -> Result { let dir = root.join(sub); ensure_outside_repo(&dir)?; @@ -188,6 +196,17 @@ mod tests { ); } + #[test] + fn empty_config_env_is_ignored() { + let empty = |k: &str| (k == "VICTORY_CONFIG").then(OsString::new); + assert_eq!(explicit_config_path(empty), None); + let set = |k: &str| (k == "VICTORY_CONFIG").then(|| OsString::from("custom.toml")); + assert_eq!( + explicit_config_path(set), + Some(PathBuf::from("custom.toml")) + ); + } + #[test] fn example_config_parses() { let text = include_str!("../../../victory.example.toml");