58
58
let mut ita = path. components ( ) ;
59
59
let mut itb = base. components ( ) ;
60
60
let mut comps: Vec < Component > = vec ! [ ] ;
61
+
62
+ // ./foo and foo are the same
63
+ if let Some ( Component :: CurDir ) = ita. clone ( ) . next ( ) {
64
+ ita. next ( ) ;
65
+ }
66
+ if let Some ( Component :: CurDir ) = itb. clone ( ) . next ( ) {
67
+ itb. next ( ) ;
68
+ }
69
+
61
70
loop {
62
71
match ( ita. next ( ) , itb. next ( ) ) {
63
72
( None , None ) => break ,
@@ -136,6 +145,15 @@ mod utf8_paths {
136
145
let mut ita = path. components ( ) ;
137
146
let mut itb = base. components ( ) ;
138
147
let mut comps: Vec < Utf8Component > = vec ! [ ] ;
148
+
149
+ // ./foo and foo are the same
150
+ if let Some ( Utf8Component :: CurDir ) = ita. clone ( ) . next ( ) {
151
+ ita. next ( ) ;
152
+ }
153
+ if let Some ( Utf8Component :: CurDir ) = itb. clone ( ) . next ( ) {
154
+ itb. next ( ) ;
155
+ }
156
+
139
157
loop {
140
158
match ( ita. next ( ) , itb. next ( ) ) {
141
159
( None , None ) => break ,
@@ -198,6 +216,9 @@ mod tests {
198
216
assert_diff_paths ( "./foo" , "./foo" , Some ( "" ) ) ;
199
217
assert_diff_paths ( "/foo" , "/foo" , Some ( "" ) ) ;
200
218
assert_diff_paths ( "foo" , "foo" , Some ( "" ) ) ;
219
+ assert_diff_paths ( "./foo" , "foo" , Some ( "" ) ) ;
220
+ assert_diff_paths ( "foo" , "./foo" , Some ( "" ) ) ;
221
+ assert_diff_paths ( "foo/foo" , "./foo/foo" , Some ( "" ) ) ;
201
222
202
223
assert_diff_paths ( "../foo/bar/baz" , "../foo/bar/baz" , Some ( "" . into ( ) ) ) ;
203
224
assert_diff_paths ( "foo/bar/baz" , "foo/bar/baz" , Some ( "" ) ) ;
@@ -221,6 +242,8 @@ mod tests {
221
242
assert_diff_paths ( "../foo" , "../bar" , Some ( "../foo" ) ) ;
222
243
assert_diff_paths ( "../foo" , "../foo/bar/baz" , Some ( "../.." ) ) ;
223
244
assert_diff_paths ( "../foo/bar/baz" , "../foo" , Some ( "bar/baz" ) ) ;
245
+ assert_diff_paths ( "../foo" , "bar" , Some ( "../../foo" ) ) ;
246
+ assert_diff_paths ( "foo" , "../bar" , None ) ;
224
247
225
248
assert_diff_paths ( "foo/bar/baz" , "foo" , Some ( "bar/baz" ) ) ;
226
249
assert_diff_paths ( "foo/bar/baz" , "foo/bar" , Some ( "baz" ) ) ;
@@ -242,6 +265,10 @@ mod tests {
242
265
assert_diff_paths ( "." , "foo" , Some ( "../." ) ) ;
243
266
assert_diff_paths ( "foo" , "." , Some ( "foo" ) ) ;
244
267
assert_diff_paths ( "/foo" , "/." , Some ( "foo" ) ) ;
268
+
269
+ assert_diff_paths ( "./foo/bar/baz" , "foo" , Some ( "bar/baz" ) ) ;
270
+ assert_diff_paths ( "foo/bar/baz" , "./foo" , Some ( "bar/baz" ) ) ;
271
+ assert_diff_paths ( "./foo/bar/baz" , "./foo" , Some ( "bar/baz" ) ) ;
245
272
}
246
273
247
274
fn assert_diff_paths ( path : & str , base : & str , expected : Option < & str > ) {
0 commit comments