Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions e2e/config/test_override_config_filenames_empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Regression test: MISE_OVERRIDE_CONFIG_FILENAMES set to empty string
# should not cause a panic. An empty value should be treated the same
# as the variable being unset (i.e., use default config filenames).
#
# Background: split(':') on "" produces [""], a set with one empty-string
# entry. This non-empty set bypasses the default config filename list and
# injects "" as a config filename, which eventually causes a panic in
# config_root() during Config::load.
#
# See: https://github.com/jdx/mise/pull/9076

echo 'tools.dummy = "1"' >mise.toml

# Empty string — should behave like unset (use mise.toml)
MISE_OVERRIDE_CONFIG_FILENAMES="" assert_succeed "mise ls"

# Colon-only — split produces ["", ""], both empty, should behave like unset
MISE_OVERRIDE_CONFIG_FILENAMES=":" assert_succeed "mise ls"
Comment thread
greptile-apps[bot] marked this conversation as resolved.

# Trailing/leading colons — should ignore empty segments
echo 'tools.dummy = "2"' >mise.ci.toml
MISE_OVERRIDE_CONFIG_FILENAMES=":mise.ci.toml:" assert "mise ls dummy" "dummy 2.0.0 (missing) ~/workdir/mise.ci.toml 2"
34 changes: 32 additions & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ pub static MISE_DEFAULT_CONFIG_FILENAME: Lazy<String> = Lazy::new(|| {
pub static MISE_OVERRIDE_TOOL_VERSIONS_FILENAMES: Lazy<Option<IndexSet<String>>> =
Lazy::new(|| match var("MISE_OVERRIDE_TOOL_VERSIONS_FILENAMES") {
Ok(v) if v == "none" => Some([].into()),
Ok(v) => Some(v.split(':').map(|s| s.to_string()).collect()),
Ok(v) => Some(split_colon_list(&v)),
Err(_) => {
miserc::get_override_tool_versions_filenames().map(|v| v.iter().cloned().collect())
}
});
pub static MISE_OVERRIDE_CONFIG_FILENAMES: Lazy<IndexSet<String>> =
Lazy::new(|| match var("MISE_OVERRIDE_CONFIG_FILENAMES") {
Ok(v) => v.split(':').map(|s| s.to_string()).collect(),
Ok(v) => split_colon_list(&v),
Err(_) => miserc::get_override_config_filenames()
.map(|v| v.iter().cloned().collect())
.unwrap_or_default(),
Expand Down Expand Up @@ -738,6 +738,18 @@ fn linux_glibc_version() -> Option<(u32, u32)> {
None
}

/// Split a colon-separated string into a set, filtering empty segments.
/// Empty segments arise from empty strings, leading/trailing colons, or
/// consecutive colons — all of which should be ignored rather than
/// injected as empty paths into config discovery.
fn split_colon_list(value: &str) -> IndexSet<String> {
value
.split(':')
.filter(|s| !s.is_empty())
.map(|s| s.to_string())
.collect()
}

fn filename(path: &str) -> &str {
path.rsplit_once(path::MAIN_SEPARATOR_STR)
.map(|(_, file)| file)
Expand Down Expand Up @@ -834,6 +846,24 @@ mod tests {
remove_var("MISE_TEST_PATH");
}

#[test]
fn test_split_colon_list() {
let cases: Vec<(&str, Vec<&str>)> = vec![
("", vec![]), // empty string — was causing panic
(":", vec![]), // colon only
(":::", vec![]), // multiple colons
("mise.toml", vec!["mise.toml"]),
("a:b", vec!["a", "b"]),
(":a:b:", vec!["a", "b"]), // leading/trailing colons
("a::b", vec!["a", "b"]), // consecutive colons
];
for (input, expected) in cases {
let result = split_colon_list(input);
let expected: IndexSet<String> = expected.into_iter().map(|s| s.to_string()).collect();
assert_eq!(result, expected, "input: {input:?}");
}
}

#[test]
fn test_token_overwrite() {
// Clean up any existing environment variables that might interfere
Expand Down
Loading