From e8b7371a237451cdc73547b27311fd8d5078521f Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 5 Mar 2022 17:57:12 +0000 Subject: Unix `path::absolute`: Fix leading "." component Testing leading `.` and `..` components were missing from the unix tests. --- library/std/src/sys/unix/path.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'library/std/src/sys') diff --git a/library/std/src/sys/unix/path.rs b/library/std/src/sys/unix/path.rs index 6d6f4c8b8dc..a98a69e2db8 100644 --- a/library/std/src/sys/unix/path.rs +++ b/library/std/src/sys/unix/path.rs @@ -28,7 +28,8 @@ pub(crate) fn absolute(path: &Path) -> io::Result { // 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() { -- cgit 1.4.1-3-g733a5