mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-26 05:44:26 +00:00
Unix path::absolute
: Fix leading "." component
Testing leading `.` and `..` components were missing from the unix tests.
This commit is contained in:
parent
c8a49fc902
commit
e8b7371a23
@ -1719,6 +1719,11 @@ fn test_unix_absolute() {
|
||||
assert_eq!(absolute("///a/b/c").unwrap(), Path::new("/a/b/c"));
|
||||
assert_eq!(absolute("/a/b/c/").unwrap(), Path::new("/a/b/c/"));
|
||||
assert_eq!(absolute("/a/./b/../c/.././..").unwrap(), Path::new("/a/b/../c/../.."));
|
||||
|
||||
// Test leading `.` and `..` components
|
||||
let curdir = crate::env::current_dir().unwrap();
|
||||
assert_eq!(absolute("./a").unwrap().as_os_str(), curdir.join("a").as_os_str());
|
||||
assert_eq!(absolute("../a").unwrap().as_os_str(), curdir.join("../a").as_os_str()); // return /pwd/../a
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -28,7 +28,8 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
|
||||
// See 4.13 Pathname Resolution, IEEE Std 1003.1-2017
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
|
||||
|
||||
let mut components = path.components();
|
||||
// Get the components, skipping the redundant leading "." component if it exists.
|
||||
let mut components = path.strip_prefix(".").unwrap_or(path).components();
|
||||
let path_os = path.as_os_str().bytes();
|
||||
|
||||
let mut normalized = if path.is_absolute() {
|
||||
|
Loading…
Reference in New Issue
Block a user