mirror of
https://github.com/nushell/nushell.git
synced 2025-08-13 12:27:42 +02:00
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:
@ -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\\");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user