File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -1719,6 +1719,11 @@ fn test_unix_absolute() {
1719
1719
assert_eq ! ( absolute( "///a/b/c" ) . unwrap( ) , Path :: new( "/a/b/c" ) ) ;
1720
1720
assert_eq ! ( absolute( "/a/b/c/" ) . unwrap( ) , Path :: new( "/a/b/c/" ) ) ;
1721
1721
assert_eq ! ( absolute( "/a/./b/../c/.././.." ) . unwrap( ) , Path :: new( "/a/b/../c/../.." ) ) ;
1722
+
1723
+ // Test leading `.` and `..` components
1724
+ let curdir = crate :: env:: current_dir ( ) . unwrap ( ) ;
1725
+ assert_eq ! ( absolute( "./a" ) . unwrap( ) . as_os_str( ) , curdir. join( "a" ) . as_os_str( ) ) ;
1726
+ assert_eq ! ( absolute( "../a" ) . unwrap( ) . as_os_str( ) , curdir. join( "../a" ) . as_os_str( ) ) ; // return /pwd/../a
1722
1727
}
1723
1728
1724
1729
#[ test]
Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
28
28
// See 4.13 Pathname Resolution, IEEE Std 1003.1-2017
29
29
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
30
30
31
- let mut components = path. components ( ) ;
31
+ // Get the components, skipping the redundant leading "." component if it exists.
32
+ let mut components = path. strip_prefix ( "." ) . unwrap_or ( path) . components ( ) ;
32
33
let path_os = path. as_os_str ( ) . bytes ( ) ;
33
34
34
35
let mut normalized = if path. is_absolute ( ) {
You can’t perform that action at this time.
0 commit comments