@@ -51,23 +51,21 @@ impl PackageIdSpec {
51
51
/// assert!(PackageIdSpec::parse(spec).is_ok());
52
52
/// }
53
53
pub fn parse ( spec : & str ) -> CargoResult < PackageIdSpec > {
54
- if spec. contains ( '/' ) {
54
+ if spec. contains ( "://" ) {
55
55
if let Ok ( url) = spec. into_url ( ) {
56
56
return PackageIdSpec :: from_url ( url) ;
57
57
}
58
- if !spec. contains ( "://" ) {
59
- if spec. starts_with ( '/' ) {
60
- // This is out of current pkgid spec.
61
- // Only for fixing rust-lang/cargo#9041
62
- bail ! (
63
- "pkgid urls with local paths must be prefixed \
64
- with a `file://` scheme: {}",
65
- spec
66
- )
67
- }
68
- if let Ok ( url) = Url :: parse ( & format ! ( "cargo://{}" , spec) ) {
69
- return PackageIdSpec :: from_url ( url) ;
70
- }
58
+ } else if spec. contains ( '/' ) || spec. contains ( '\\' ) {
59
+ let abs = std:: env:: current_dir ( ) . unwrap_or_default ( ) . join ( spec) ;
60
+ if abs. exists ( ) {
61
+ let maybe_url = Url :: from_file_path ( abs)
62
+ . map_or_else ( |_| "a file:// URL" . to_string ( ) , |url| url. to_string ( ) ) ;
63
+ bail ! (
64
+ "package ID specification `{}` looks like a file path, \
65
+ maybe try {}",
66
+ spec,
67
+ maybe_url
68
+ ) ;
71
69
}
72
70
}
73
71
let mut parts = spec. splitn ( 2 , ':' ) ;
@@ -284,11 +282,7 @@ impl fmt::Display for PackageIdSpec {
284
282
let mut printed_name = false ;
285
283
match self . url {
286
284
Some ( ref url) => {
287
- if url. scheme ( ) == "cargo" {
288
- write ! ( f, "{}{}" , url. host( ) . unwrap( ) , url. path( ) ) ?;
289
- } else {
290
- write ! ( f, "{}" , url) ?;
291
- }
285
+ write ! ( f, "{}" , url) ?;
292
286
if url. path_segments ( ) . unwrap ( ) . next_back ( ) . unwrap ( ) != & * self . name {
293
287
printed_name = true ;
294
288
write ! ( f, "#{}" , self . name) ?;
@@ -342,51 +336,27 @@ mod tests {
342
336
}
343
337
344
338
ok (
345
- "https://crates.io/foo#1.2.3" ,
346
- PackageIdSpec {
347
- name : InternedString :: new ( "foo" ) ,
348
- version : Some ( "1.2.3" . to_semver ( ) . unwrap ( ) ) ,
349
- url : Some ( Url :: parse ( "https://crates.io/foo" ) . unwrap ( ) ) ,
350
- } ,
351
- ) ;
352
- ok (
353
- "https://crates.io/foo#bar:1.2.3" ,
354
- PackageIdSpec {
355
- name : InternedString :: new ( "bar" ) ,
356
- version : Some ( "1.2.3" . to_semver ( ) . unwrap ( ) ) ,
357
- url : Some ( Url :: parse ( "https://crates.io/foo" ) . unwrap ( ) ) ,
358
- } ,
359
- ) ;
360
- ok (
361
- "crates.io/foo" ,
339
+ "https://crates.io/foo" ,
362
340
PackageIdSpec {
363
341
name : InternedString :: new ( "foo" ) ,
364
342
version : None ,
365
- url : Some ( Url :: parse ( "cargo ://crates.io/foo" ) . unwrap ( ) ) ,
343
+ url : Some ( Url :: parse ( "https ://crates.io/foo" ) . unwrap ( ) ) ,
366
344
} ,
367
345
) ;
368
346
ok (
369
- "crates.io/foo#1.2.3" ,
347
+ "https:// crates.io/foo#1.2.3" ,
370
348
PackageIdSpec {
371
349
name : InternedString :: new ( "foo" ) ,
372
350
version : Some ( "1.2.3" . to_semver ( ) . unwrap ( ) ) ,
373
- url : Some ( Url :: parse ( "cargo://crates.io/foo" ) . unwrap ( ) ) ,
374
- } ,
375
- ) ;
376
- ok (
377
- "crates.io/foo#bar" ,
378
- PackageIdSpec {
379
- name : InternedString :: new ( "bar" ) ,
380
- version : None ,
381
- url : Some ( Url :: parse ( "cargo://crates.io/foo" ) . unwrap ( ) ) ,
351
+ url : Some ( Url :: parse ( "https://crates.io/foo" ) . unwrap ( ) ) ,
382
352
} ,
383
353
) ;
384
354
ok (
385
- "crates.io/foo#bar:1.2.3" ,
355
+ "https:// crates.io/foo#bar:1.2.3" ,
386
356
PackageIdSpec {
387
357
name : InternedString :: new ( "bar" ) ,
388
358
version : Some ( "1.2.3" . to_semver ( ) . unwrap ( ) ) ,
389
- url : Some ( Url :: parse ( "cargo ://crates.io/foo" ) . unwrap ( ) ) ,
359
+ url : Some ( Url :: parse ( "https ://crates.io/foo" ) . unwrap ( ) ) ,
390
360
} ,
391
361
) ;
392
362
ok (
@@ -414,7 +384,6 @@ mod tests {
414
384
assert ! ( PackageIdSpec :: parse( "baz:1.0" ) . is_err( ) ) ;
415
385
assert ! ( PackageIdSpec :: parse( "https://baz:1.0" ) . is_err( ) ) ;
416
386
assert ! ( PackageIdSpec :: parse( "https://#baz:1.0" ) . is_err( ) ) ;
417
- assert ! ( PackageIdSpec :: parse( "/baz" ) . is_err( ) ) ;
418
387
}
419
388
420
389
#[ test]
0 commit comments