mirror of
https://github.com/nushell/nushell.git
synced 2025-07-09 02:48:17 +02:00
Fix trailing slash in PWD set by cd
(#12760)
# Description Fixes #12758. #12662 introduced a bug where calling `cd` with a path with a trailing slash would cause `PWD` to be set to a path including a trailing slash, which is not allowed. This adds a helper to `nu_path` to remove this, and uses it in the `cd` command to clean it up before setting `PWD`. # Tests + Formatting I added some tests to make sure we don't regress on this in the future. - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib`
This commit is contained in:
@ -100,6 +100,9 @@ impl Command for Cd {
|
||||
}
|
||||
};
|
||||
|
||||
// Strip the trailing slash from the new path. This is required for PWD.
|
||||
let path = nu_path::strip_trailing_slash(&path);
|
||||
|
||||
// Set OLDPWD.
|
||||
// We're using `Stack::get_env_var()` instead of `EngineState::cwd()` to avoid a conversion roundtrip.
|
||||
if let Some(oldpwd) = stack.get_env_var(engine_state, "PWD") {
|
||||
|
Reference in New Issue
Block a user