@@ -37,12 +37,12 @@ fn path_join_handling() {
37
37
let absolute = p ( "/absolute" ) ;
38
38
assert ! (
39
39
absolute. is_relative( ) ,
40
- "on Windows, absolute linux paths are considered relative"
40
+ "on Windows, absolute Linux paths are considered relative (and relative to the current drive) "
41
41
) ;
42
42
let bs_absolute = p ( "\\ absolute" ) ;
43
43
assert ! (
44
44
absolute. is_relative( ) ,
45
- "on Windows, strange single-backslash paths are relative"
45
+ "on Windows, strange single-backslash paths are relative (and relative to the current drive) "
46
46
) ;
47
47
assert_eq ! (
48
48
p( "relative" ) . join( absolute) ,
@@ -58,7 +58,7 @@ fn path_join_handling() {
58
58
assert_eq ! (
59
59
p( "c:" ) . join( "relative" ) ,
60
60
p( "c:relative" ) ,
61
- "absolute + relative = strange joined result with missing slash - but that shouldn't usually happen "
61
+ "absolute + relative = strange joined result with missing back- slash, but it's a valid path that works just like `c: \r elative` "
62
62
) ;
63
63
assert_eq ! (
64
64
p( "c:\\ " ) . join( "relative" ) ,
@@ -69,34 +69,52 @@ fn path_join_handling() {
69
69
assert_eq ! (
70
70
p( "\\ \\ ?\\ base" ) . join( absolute) ,
71
71
p( "\\ \\ ?\\ base\\ absolute" ) ,
72
- "absolute1 + absolute2 = joined result with backslash"
72
+ "absolute1 + unix-absolute2 = joined result with backslash"
73
+ ) ;
74
+ assert_eq ! (
75
+ p( "\\ \\ .\\ base" ) . join( absolute) ,
76
+ p( "\\ \\ .\\ base\\ absolute" ) ,
77
+ "absolute1 + absolute2 = joined result with backslash (device relative)"
73
78
) ;
74
79
assert_eq ! (
75
80
p( "\\ \\ ?\\ base" ) . join( bs_absolute) ,
76
81
p( "\\ \\ ?\\ base\\ absolute" ) ,
77
82
"absolute1 + absolute2 = joined result"
78
83
) ;
84
+ assert_eq ! (
85
+ p( "\\ \\ .\\ base" ) . join( bs_absolute) ,
86
+ p( "\\ \\ .\\ base\\ absolute" ) ,
87
+ "absolute1 + absolute2 = joined result (device relative)"
88
+ ) ;
79
89
90
+ assert_eq ! ( p( "/" ) . join( "C:" ) , p( "C:" ) , "unix-absolute + win-drive = win-drive" ) ;
80
91
assert_eq ! (
81
- p( "/" ) . join( "C:" ) ,
92
+ p( "d: /" ) . join( "C:" ) ,
82
93
p( "C:" ) ,
83
- "unix-absolute + win-absolute = win-absolute "
94
+ "d-drive + c-drive = c-drive - interesting, as C: is supposed to be relative "
84
95
) ;
85
96
assert_eq ! (
86
- p( "/ " ) . join( "C:/ " ) ,
97
+ p( "d: \\ " ) . join( "C:\\ " ) ,
87
98
p( "C:\\ " ) ,
88
- "unix-absolute + win-absolute = win-result, strangely enough it changed the trailing slash to backslash, so better not have trailing slashes "
99
+ "d-drive-with-bs + c-drive-with-bs = c-drive-with-bs - nothing special happens with backslashes "
89
100
) ;
90
101
assert_eq ! (
91
- p( "/" ) . join( "C:\\ " ) ,
102
+ p( "c:\\ " ) . join( "\\ \\ .\\ " ) ,
103
+ p( "\\ \\ .\\ " ) ,
104
+ "d-drive-with-bs + device-relative-unc = device-relative-unc"
105
+ ) ;
106
+ assert_eq ! (
107
+ p( "/" ) . join( "C:/" ) ,
92
108
p( "C:\\ " ) ,
93
- "unix-absolute + win-absolute = win-result "
109
+ "unix-absolute + win-drive = win-drive, strangely enough it changed the trailing slash to backslash, so better not have trailing slashes "
94
110
) ;
111
+ assert_eq ! ( p( "/" ) . join( "C:\\ " ) , p( "C:\\ " ) , "unix-absolute + win-drive = win-drive" ) ;
95
112
assert_eq ! (
96
- p( "relative " ) . join( "C:" ) ,
113
+ p( "\\ \\ . " ) . join( "C:" ) ,
97
114
p( "C:" ) ,
98
- "relative + win-absolute = win-result "
115
+ "device- relative-unc + win-drive-relative = win-drive-relative - c: was supposed to be relative, but it's not acting like it. "
99
116
) ;
117
+ assert_eq ! ( p( "relative" ) . join( "C:" ) , p( "C:" ) , "relative + win-drive = win-drive" ) ;
100
118
101
119
assert_eq ! (
102
120
p( "/" ) . join( "\\ \\ localhost" ) ,
@@ -202,6 +220,17 @@ fn relative_components_are_invalid() {
202
220
if cfg!( windows) { ".\\ a\\ b" } else { "./a/b" } ,
203
221
"dot is silently ignored"
204
222
) ;
223
+ s. make_relative_path_current ( "a//b/" . as_ref ( ) , & mut r)
224
+ . expect ( "multiple-slashes are ignored" ) ;
225
+ assert_eq ! (
226
+ r,
227
+ Record {
228
+ push_dir: 2 ,
229
+ dirs: vec![ "." . into( ) , "./a" . into( ) ] ,
230
+ push: 2 ,
231
+ } ,
232
+ "nothing changed"
233
+ ) ;
205
234
}
206
235
207
236
#[ test]
@@ -226,7 +255,7 @@ fn absolute_paths_are_invalid() -> crate::Result {
226
255
assert_eq ! (
227
256
s. current( ) ,
228
257
p( "./b\\ " ) ,
229
- "trailing back-slashes are fine both on Windows and unix - on Unix it's part fo the filename"
258
+ "trailing backslashes are fine both on Windows and Unix - on Unix it's part fo the filename"
230
259
) ;
231
260
232
261
#[ cfg( windows) ]
@@ -235,22 +264,28 @@ fn absolute_paths_are_invalid() -> crate::Result {
235
264
assert_eq ! (
236
265
err. to_string( ) ,
237
266
"Input path \" \\ \" contains relative or absolute components" ,
238
- "on windows , backslashes are considered absolute and replace the base if it is relative, \
267
+ "on Windows , backslashes are considered absolute and replace the base if it is relative, \
239
268
hence they are forbidden."
240
269
) ;
241
270
242
271
let err = s. make_relative_path_current ( "c:" . as_ref ( ) , & mut r) . unwrap_err ( ) ;
243
272
assert_eq ! (
244
273
err. to_string( ) ,
245
274
"Input path \" c:\" contains relative or absolute components" ,
246
- "on windows, drive-letters are also absolute"
275
+ "on Windows, drive-letters without trailing backslash or slash are also absolute (even though they ought to be relative)"
276
+ ) ;
277
+ let err = s. make_relative_path_current ( "c:\\ " . as_ref ( ) , & mut r) . unwrap_err ( ) ;
278
+ assert_eq ! (
279
+ err. to_string( ) ,
280
+ "Input path \" c:\\ \" contains relative or absolute components" ,
281
+ "on Windows, drive-letters are absolute, which is expected"
247
282
) ;
248
283
249
284
s. make_relative_path_current ( "֍:" . as_ref ( ) , & mut r) ?;
250
285
assert_eq ! (
251
286
s. current( ) . to_string_lossy( ) ,
252
287
".\\ ֍:" ,
253
- "on windows, any unicode character will do as virtual drive-letter actually with `subst`, \
288
+ "on Windows, almost any unicode character will do as virtual drive-letter actually with `subst`, \
254
289
but we just turn it into a presumably invalid path which is fine, i.e. we get a joined path"
255
290
) ;
256
291
let err = s
@@ -440,7 +475,7 @@ fn delegate_calls_are_consistent() -> crate::Result {
440
475
dirs: dirs. clone( ) ,
441
476
push: 19 ,
442
477
} ,
443
- "a backslash is a normal character outside of windows , so it's fine to have it as component"
478
+ "a backslash is a normal character outside of Windows , so it's fine to have it as component"
444
479
) ;
445
480
446
481
s. make_relative_path_current ( "\\ " . as_ref ( ) , & mut r) ?;
0 commit comments