Skip to content

Commit f4c7ed1

Browse files
committed
fix(pkgid): Allow open namespaces in PackageIdSpec's
1 parent c81e82d commit f4c7ed1

File tree

2 files changed

+62
-24
lines changed

2 files changed

+62
-24
lines changed

crates/cargo-util-schemas/src/core/package_id_spec.rs

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ impl PackageIdSpec {
210210
}
211211

212212
fn parse_spec(spec: &str) -> Result<Option<(String, Option<PartialVersion>)>> {
213-
let Some((name, ver)) = spec.split_once([':', '@']) else {
213+
let Some((name, ver)) = spec
214+
.rsplit_once('@')
215+
.or_else(|| spec.rsplit_once(':').filter(|(n, _)| !n.ends_with(':')))
216+
else {
214217
return Ok(None);
215218
};
216219
let name = name.to_owned();
@@ -438,7 +441,16 @@ mod tests {
438441
},
439442
"foo",
440443
);
441-
err!("foo::bar", ErrorKind::PartialVersion(_));
444+
ok(
445+
"foo::bar",
446+
PackageIdSpec {
447+
name: String::from("foo::bar"),
448+
version: None,
449+
url: None,
450+
kind: None,
451+
},
452+
"foo::bar",
453+
);
442454
ok(
443455
"foo:1.2.3",
444456
PackageIdSpec {
@@ -449,7 +461,16 @@ mod tests {
449461
},
450462
451463
);
452-
err!("foo::bar:1.2.3", ErrorKind::PartialVersion(_));
464+
ok(
465+
"foo::bar:1.2.3",
466+
PackageIdSpec {
467+
name: String::from("foo::bar"),
468+
version: Some("1.2.3".parse().unwrap()),
469+
url: None,
470+
kind: None,
471+
},
472+
473+
);
453474
ok(
454475
455476
PackageIdSpec {
@@ -460,7 +481,16 @@ mod tests {
460481
},
461482
462483
);
463-
err!("foo::[email protected]", ErrorKind::PartialVersion(_));
484+
ok(
485+
486+
PackageIdSpec {
487+
name: String::from("foo::bar"),
488+
version: Some("1.2.3".parse().unwrap()),
489+
url: None,
490+
kind: None,
491+
},
492+
493+
);
464494
ok(
465495
466496
PackageIdSpec {
@@ -635,9 +665,15 @@ mod tests {
635665
},
636666
"path+file:///path/to/my/project/foo#bar",
637667
);
638-
err!(
668+
ok(
669+
"path+file:///path/to/my/project/foo#foo::bar",
670+
PackageIdSpec {
671+
name: String::from("foo::bar"),
672+
version: None,
673+
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
674+
kind: Some(SourceKind::Path),
675+
},
639676
"path+file:///path/to/my/project/foo#foo::bar",
640-
ErrorKind::PartialVersion(_)
641677
);
642678
ok(
643679
"path+file:///path/to/my/project/foo#bar:1.1.8",
@@ -649,9 +685,15 @@ mod tests {
649685
},
650686
"path+file:///path/to/my/project/foo#[email protected]",
651687
);
652-
err!(
688+
ok(
653689
"path+file:///path/to/my/project/foo#foo::bar:1.1.8",
654-
ErrorKind::PartialVersion(_)
690+
PackageIdSpec {
691+
name: String::from("foo::bar"),
692+
version: Some("1.1.8".parse().unwrap()),
693+
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
694+
kind: Some(SourceKind::Path),
695+
},
696+
"path+file:///path/to/my/project/foo#foo::[email protected]",
655697
);
656698
ok(
657699
"path+file:///path/to/my/project/foo#[email protected]",
@@ -663,9 +705,15 @@ mod tests {
663705
},
664706
"path+file:///path/to/my/project/foo#[email protected]",
665707
);
666-
err!(
708+
ok(
709+
"path+file:///path/to/my/project/foo#foo::[email protected]",
710+
PackageIdSpec {
711+
name: String::from("foo::bar"),
712+
version: Some("1.1.8".parse().unwrap()),
713+
url: Some(Url::parse("file:///path/to/my/project/foo").unwrap()),
714+
kind: Some(SourceKind::Path),
715+
},
667716
"path+file:///path/to/my/project/foo#foo::[email protected]",
668-
ErrorKind::PartialVersion(_)
669717
);
670718
}
671719

@@ -676,8 +724,8 @@ mod tests {
676724
err!("baz@", ErrorKind::PartialVersion(_));
677725
err!("baz@*", ErrorKind::PartialVersion(_));
678726
err!("baz@^1.0", ErrorKind::PartialVersion(_));
679-
err!("https://baz:1.0", ErrorKind::PartialVersion(_));
680-
err!("https://#baz:1.0", ErrorKind::PartialVersion(_));
727+
err!("https://baz:1.0", ErrorKind::NameValidation(_));
728+
err!("https://#baz:1.0", ErrorKind::NameValidation(_));
681729
err!(
682730
"foobar+https://github.com/rust-lang/crates.io-index",
683731
ErrorKind::UnsupportedProtocol(_)

tests/testsuite/open_namespaces.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,9 @@ fn update_spec_accepts_namespaced_name() {
379379
.run();
380380
p.cargo("update foo::bar")
381381
.masquerade_as_nightly_cargo(&["open-namespaces"])
382-
.with_status(101)
383382
.with_stdout_data(str![""])
384383
.with_stderr_data(str![[r#"
385-
[ERROR] invalid package ID specification: `foo::bar`
386-
387-
Did you mean `foo::bar`?
388-
389-
Caused by:
390-
expected a version like "1.32"
384+
[LOCKING] 0 packages to latest compatible versions
391385
392386
"#]])
393387
.run()
@@ -415,13 +409,9 @@ fn update_spec_accepts_namespaced_pkgid() {
415409
.run();
416410
p.cargo(&format!("update path+{}#foo::[email protected]", p.url()))
417411
.masquerade_as_nightly_cargo(&["open-namespaces"])
418-
.with_status(101)
419412
.with_stdout_data(str![""])
420413
.with_stderr_data(str![[r#"
421-
[ERROR] invalid package ID specification: `path+[ROOTURL]/foo#foo::[email protected]`
422-
423-
Caused by:
424-
expected a version like "1.32"
414+
[LOCKING] 0 packages to latest compatible versions
425415
426416
"#]])
427417
.run()

0 commit comments

Comments
 (0)