mirror of
https://github.com/nushell/nushell
synced 2025-01-13 13:49:21 +00:00
Only run from_string
conversion on strings (#14509)
# Description #14249 loaded `convert_env_values()` several times to force more updates to `ENV_CONVERSION`. This allows the user to treat variables as structured data inside `config.nu` (and others). Unfortunately, `convert_env_values()` did not originally anticipate being called more than once, so it would attempt to re-convert values that had already been converted. This usually leads to an error in the conversion closure. With this PR, values are only converted with `from_string` if they are still strings; otherwise they are skipped and their existing value is used. # User-Facing Changes No user-facing change when compared to 0.100, since closures written for 0.100's `ENV_CONVERSION` now work again without errors. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` - # After Submitting Will remove the "workaround" from the Config doc preview.
This commit is contained in:
parent
75ced3e945
commit
fc29d82614
1 changed files with 13 additions and 7 deletions
|
@ -33,14 +33,20 @@ pub fn convert_env_values(engine_state: &mut EngineState, stack: &Stack) -> Resu
|
||||||
let env_vars = engine_state.render_env_vars();
|
let env_vars = engine_state.render_env_vars();
|
||||||
|
|
||||||
for (name, val) in env_vars {
|
for (name, val) in env_vars {
|
||||||
match get_converted_value(engine_state, stack, name, val, "from_string") {
|
if let Value::String { .. } = val {
|
||||||
ConversionResult::Ok(v) => {
|
// Only run from_string on string values
|
||||||
let _ = new_scope.insert(name.to_string(), v);
|
match get_converted_value(engine_state, stack, name, val, "from_string") {
|
||||||
}
|
ConversionResult::Ok(v) => {
|
||||||
ConversionResult::ConversionError(e) => error = error.or(Some(e)),
|
let _ = new_scope.insert(name.to_string(), v);
|
||||||
ConversionResult::CellPathError => {
|
}
|
||||||
let _ = new_scope.insert(name.to_string(), val.clone());
|
ConversionResult::ConversionError(e) => error = error.or(Some(e)),
|
||||||
|
ConversionResult::CellPathError => {
|
||||||
|
let _ = new_scope.insert(name.to_string(), val.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Skip values that are already converted (not a string)
|
||||||
|
let _ = new_scope.insert(name.to_string(), val.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue