Skip to content

Commit 1ee261e

Browse files
committed
fix(pkgid): let absolute local path fail to pase
1 parent cfd45da commit 1ee261e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/cargo/core/package_id_spec.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ impl PackageIdSpec {
5656
return PackageIdSpec::from_url(url);
5757
}
5858
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+
}
5968
if let Ok(url) = Url::parse(&format!("cargo://{}", spec)) {
6069
return PackageIdSpec::from_url(url);
6170
}
@@ -97,9 +106,6 @@ impl PackageIdSpec {
97106

98107
/// Tries to convert a valid `Url` to a `PackageIdSpec`.
99108
fn from_url(mut url: Url) -> CargoResult<PackageIdSpec> {
100-
if url.host().is_none() {
101-
bail!("pkgid urls must have a host: {}", url)
102-
}
103109
if url.query().is_some() {
104110
bail!("cannot have a query string in a pkgid: {}", url)
105111
}
@@ -279,8 +285,7 @@ impl fmt::Display for PackageIdSpec {
279285
match self.url {
280286
Some(ref url) => {
281287
if url.scheme() == "cargo" {
282-
let host = url.host().unwrap_or(url::Host::Domain(""));
283-
write!(f, "{}{}", host, url.path())?;
288+
write!(f, "{}{}", url.host().unwrap(), url.path())?;
284289
} else {
285290
write!(f, "{}", url)?;
286291
}
@@ -409,7 +414,6 @@ mod tests {
409414
assert!(PackageIdSpec::parse("baz:1.0").is_err());
410415
assert!(PackageIdSpec::parse("https://baz:1.0").is_err());
411416
assert!(PackageIdSpec::parse("https://#baz:1.0").is_err());
412-
assert!(PackageIdSpec::parse("file:///baz").is_err());
413417
assert!(PackageIdSpec::parse("/baz").is_err());
414418
}
415419

0 commit comments

Comments
 (0)