From 9ed944312f13b9c401d56cb377dc9fd616ce11fe Mon Sep 17 00:00:00 2001 From: Wind Date: Tue, 7 Jan 2025 07:39:03 +0800 Subject: [PATCH] auto cd should not canonicalize symbolic path (#14708) # Description Fixes: #13158 To fix the issue for auto-cd feature, just need to use `EngineState::cwd` instead of `nu_engine::env::current_dir_str` # User-Facing Changes ## Before ```shell > cd ~ > ln -s /tmp test_link; cd test_link > .. > $env.PWD / ``` ## After ```shell > cd ~ > ln -s /tmp test_link; cd test_link > .. > $env.PWD # it should output home directory. ``` # Tests + Formatting Update a test under `auto_cd_symlink` --- crates/nu-cli/src/repl.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 1fe5109cfc..5d27dea59f 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -809,8 +809,10 @@ fn parse_operation( ) -> Result { let tokens = lex(s.as_bytes(), 0, &[], &[], false); // Check if this is a single call to a directory, if so auto-cd - #[allow(deprecated)] - let cwd = nu_engine::env::current_dir_str(engine_state, stack).unwrap_or_default(); + let cwd = engine_state + .cwd(Some(stack)) + .map(|p| p.to_string_lossy().to_string()) + .unwrap_or_default(); let mut orig = s.clone(); if orig.starts_with('`') { orig = trim_quotes_str(&orig).to_string() @@ -1570,6 +1572,13 @@ mod test_auto_cd { symlink(&dir, &link).unwrap(); let input = if cfg!(windows) { r".\link" } else { "./link" }; check(tempdir, input, link); + + let dir = tempdir.join("foo").join("bar"); + std::fs::create_dir_all(&dir).unwrap(); + let link = tempdir.join("link2"); + symlink(&dir, &link).unwrap(); + let input = ".."; + check(link, input, tempdir); } #[test]