-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pkgid): Allow open namespaces in PackageIdSpec's
- Loading branch information
Showing
2 changed files
with
62 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,7 +210,10 @@ impl PackageIdSpec { | |
} | ||
|
||
fn parse_spec(spec: &str) -> Result<Option<(String, Option<PartialVersion>)>> { | ||
let Some((name, ver)) = spec.split_once([':', '@']) else { | ||
let Some((name, ver)) = spec | ||
.rsplit_once('@') | ||
.or_else(|| spec.rsplit_once(':').filter(|(n, _)| !n.ends_with(':'))) | ||
else { | ||
return Ok(None); | ||
}; | ||
let name = name.to_owned(); | ||
|
@@ -438,7 +441,16 @@ mod tests { | |
}, | ||
"foo", | ||
); | ||
err!("foo::bar", ErrorKind::PartialVersion(_)); | ||
ok( | ||
"foo::bar", | ||
PackageIdSpec { | ||
name: String::from("foo::bar"), | ||
version: None, | ||
url: None, | ||
kind: None, | ||
}, | ||
"foo::bar", | ||
); | ||
ok( | ||
"foo:1.2.3", | ||
PackageIdSpec { | ||
|
@@ -449,7 +461,16 @@ mod tests { | |
}, | ||
"[email protected]", | ||
); | ||
err!("foo::bar:1.2.3", ErrorKind::PartialVersion(_)); | ||
ok( | ||
"foo::bar:1.2.3", | ||
PackageIdSpec { | ||
name: String::from("foo::bar"), | ||
version: Some("1.2.3".parse().unwrap()), | ||
url: None, | ||
kind: None, | ||
}, | ||
"foo::[email protected]", | ||
); | ||
ok( | ||
"[email protected]", | ||
PackageIdSpec { | ||
|
@@ -460,7 +481,16 @@ mod tests { | |
}, | ||
"[email protected]", | ||
); | ||
err!("foo::[email protected]", ErrorKind::PartialVersion(_)); | ||
ok( | ||
"foo::[email protected]", | ||
PackageIdSpec { | ||
name: String::from("foo::bar"), | ||
version: Some("1.2.3".parse().unwrap()), | ||
url: None, | ||
kind: None, | ||
}, | ||
"foo::[email protected]", | ||
); | ||
ok( | ||
"[email protected]", | ||
PackageIdSpec { | ||
|
@@ -635,9 +665,15 @@ mod tests { | |
}, | ||
"path+file:///path/to/my/project/foo#bar", | ||
); | ||
err!( | ||
ok( | ||
"path+file:///path/to/my/project/foo#foo::bar", | ||
PackageIdSpec { | ||
name: String::from("foo::bar"), | ||
version: None, | ||
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()), | ||
kind: Some(SourceKind::Path), | ||
}, | ||
"path+file:///path/to/my/project/foo#foo::bar", | ||
ErrorKind::PartialVersion(_) | ||
); | ||
ok( | ||
"path+file:///path/to/my/project/foo#bar:1.1.8", | ||
|
@@ -649,9 +685,15 @@ mod tests { | |
}, | ||
"path+file:///path/to/my/project/foo#[email protected]", | ||
); | ||
err!( | ||
ok( | ||
"path+file:///path/to/my/project/foo#foo::bar:1.1.8", | ||
ErrorKind::PartialVersion(_) | ||
PackageIdSpec { | ||
name: String::from("foo::bar"), | ||
version: Some("1.1.8".parse().unwrap()), | ||
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()), | ||
kind: Some(SourceKind::Path), | ||
}, | ||
"path+file:///path/to/my/project/foo#foo::[email protected]", | ||
); | ||
ok( | ||
"path+file:///path/to/my/project/foo#[email protected]", | ||
|
@@ -663,9 +705,15 @@ mod tests { | |
}, | ||
"path+file:///path/to/my/project/foo#[email protected]", | ||
); | ||
err!( | ||
ok( | ||
"path+file:///path/to/my/project/foo#foo::[email protected]", | ||
PackageIdSpec { | ||
name: String::from("foo::bar"), | ||
version: Some("1.1.8".parse().unwrap()), | ||
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()), | ||
kind: Some(SourceKind::Path), | ||
}, | ||
"path+file:///path/to/my/project/foo#foo::[email protected]", | ||
ErrorKind::PartialVersion(_) | ||
); | ||
} | ||
|
||
|
@@ -676,8 +724,8 @@ mod tests { | |
err!("baz@", ErrorKind::PartialVersion(_)); | ||
err!("baz@*", ErrorKind::PartialVersion(_)); | ||
err!("baz@^1.0", ErrorKind::PartialVersion(_)); | ||
err!("https://baz:1.0", ErrorKind::PartialVersion(_)); | ||
err!("https://#baz:1.0", ErrorKind::PartialVersion(_)); | ||
err!("https://baz:1.0", ErrorKind::NameValidation(_)); | ||
err!("https://#baz:1.0", ErrorKind::NameValidation(_)); | ||
err!( | ||
"foobar+https://github.com/rust-lang/crates.io-index", | ||
ErrorKind::UnsupportedProtocol(_) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,15 +379,9 @@ fn update_spec_accepts_namespaced_name() { | |
.run(); | ||
p.cargo("update foo::bar") | ||
.masquerade_as_nightly_cargo(&["open-namespaces"]) | ||
.with_status(101) | ||
.with_stdout_data(str![""]) | ||
.with_stderr_data(str![[r#" | ||
[ERROR] invalid package ID specification: `foo::bar` | ||
Did you mean `foo::bar`? | ||
Caused by: | ||
expected a version like "1.32" | ||
[LOCKING] 0 packages to latest compatible versions | ||
"#]]) | ||
.run() | ||
|
@@ -415,13 +409,9 @@ fn update_spec_accepts_namespaced_pkgid() { | |
.run(); | ||
p.cargo(&format!("update path+{}#foo::[email protected]", p.url())) | ||
.masquerade_as_nightly_cargo(&["open-namespaces"]) | ||
.with_status(101) | ||
.with_stdout_data(str![""]) | ||
.with_stderr_data(str![[r#" | ||
[ERROR] invalid package ID specification: `path+[ROOTURL]/foo#foo::[email protected]` | ||
Caused by: | ||
expected a version like "1.32" | ||
[LOCKING] 0 packages to latest compatible versions | ||
"#]]) | ||
.run() | ||
|