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() {
17191719 assert_eq ! ( absolute( "///a/b/c" ) . unwrap( ) , Path :: new( "/a/b/c" ) ) ;
17201720 assert_eq ! ( absolute( "/a/b/c/" ) . unwrap( ) , Path :: new( "/a/b/c/" ) ) ;
17211721 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
17221727}
17231728
17241729#[ test]
Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
2828 // See 4.13 Pathname Resolution, IEEE Std 1003.1-2017
2929 // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
3030
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 ( ) ;
3233 let path_os = path. as_os_str ( ) . bytes ( ) ;
3334
3435 let mut normalized = if path. is_absolute ( ) {
You can’t perform that action at this time.
0 commit comments