Path expansion no longer removes trailing slashes (#12662)

This PR changes `nu_path::expand_path_with()` to no longer remove
trailing slashes. It also fixes bugs in the current implementation due
to ineffective tests (Fixes #12602).
This commit is contained in:
YizhePKU
2024-05-02 06:28:54 +08:00
committed by GitHub
parent b22d131279
commit f184a77fe1
9 changed files with 476 additions and 355 deletions

View File

@ -151,6 +151,7 @@ pub fn expand_tilde(path: impl AsRef<Path>) -> PathBuf {
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_path_eq;
use std::path::MAIN_SEPARATOR;
fn check_expanded(s: &str) {
@ -244,4 +245,23 @@ mod tests {
assert_eq!(expected_home, actual_home, "wrong home");
}
#[test]
#[cfg(not(windows))]
fn expand_tilde_preserve_trailing_slash() {
let path = PathBuf::from("~/foo/");
let home = PathBuf::from("/home");
let actual = expand_tilde_with_home(path, Some(home));
assert_path_eq!(actual, "/home/foo/");
}
#[test]
#[cfg(windows)]
fn expand_tilde_preserve_trailing_slash() {
let path = PathBuf::from("~\\foo\\");
let home = PathBuf::from("C:\\home");
let actual = expand_tilde_with_home(path, Some(home));
assert_path_eq!(actual, "C:\\home\\foo\\");
}
}