Skip to content

Commit 1bbc056

Browse files
committed
fix(pkgid): drop cargo:// support
1 parent 1ee261e commit 1bbc056

File tree

1 file changed

+19
-50
lines changed

1 file changed

+19
-50
lines changed

src/cargo/core/package_id_spec.rs

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,21 @@ impl PackageIdSpec {
5151
/// assert!(PackageIdSpec::parse(spec).is_ok());
5252
/// }
5353
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
54-
if spec.contains('/') {
54+
if spec.contains("://") {
5555
if let Ok(url) = spec.into_url() {
5656
return PackageIdSpec::from_url(url);
5757
}
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+
);
7169
}
7270
}
7371
let mut parts = spec.splitn(2, ':');
@@ -284,11 +282,7 @@ impl fmt::Display for PackageIdSpec {
284282
let mut printed_name = false;
285283
match self.url {
286284
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)?;
292286
if url.path_segments().unwrap().next_back().unwrap() != &*self.name {
293287
printed_name = true;
294288
write!(f, "#{}", self.name)?;
@@ -342,51 +336,27 @@ mod tests {
342336
}
343337

344338
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",
362340
PackageIdSpec {
363341
name: InternedString::new("foo"),
364342
version: None,
365-
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
343+
url: Some(Url::parse("https://crates.io/foo").unwrap()),
366344
},
367345
);
368346
ok(
369-
"crates.io/foo#1.2.3",
347+
"https://crates.io/foo#1.2.3",
370348
PackageIdSpec {
371349
name: InternedString::new("foo"),
372350
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()),
382352
},
383353
);
384354
ok(
385-
"crates.io/foo#bar:1.2.3",
355+
"https://crates.io/foo#bar:1.2.3",
386356
PackageIdSpec {
387357
name: InternedString::new("bar"),
388358
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()),
390360
},
391361
);
392362
ok(
@@ -414,7 +384,6 @@ mod tests {
414384
assert!(PackageIdSpec::parse("baz:1.0").is_err());
415385
assert!(PackageIdSpec::parse("https://baz:1.0").is_err());
416386
assert!(PackageIdSpec::parse("https://#baz:1.0").is_err());
417-
assert!(PackageIdSpec::parse("/baz").is_err());
418387
}
419388

420389
#[test]

0 commit comments

Comments
 (0)