diff --git a/src/controllers/krate/publish.rs b/src/controllers/krate/publish.rs index d2eaefa4e95..5ea28638ae4 100644 --- a/src/controllers/krate/publish.rs +++ b/src/controllers/krate/publish.rs @@ -247,18 +247,18 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult, BTreeMap<_, _>) = - features.into_iter().partition(|(_k, vals)| { - !vals - .iter() - .any(|v| v.starts_with("dep:") || v.contains("?/")) - }); - let (features2, v) = if features2.is_empty() { - (None, None) - } else { - (Some(features2), Some(2)) + let uses_features2_syntax = features + .iter() + .flat_map(|(_key, values)| values) + .any(|values| values.starts_with("dep:") || values.contains("?/")); + + let (features, features2) = match uses_features2_syntax { + true => (BTreeMap::new(), Some(features)), + false => (features, None), }; + let v = features2.as_ref().map(|_| 2); + // Register this crate in our local git repo. let git_crate = cargo_registry_index::Crate { name: name.0, diff --git a/src/tests/http-data/krate_publish_features_version_2.json b/src/tests/http-data/krate_publish_features_version_2.json index ddc51538c4a..c6ca8825822 100644 --- a/src/tests/http-data/krate_publish_features_version_2.json +++ b/src/tests/http-data/krate_publish_features_version_2.json @@ -44,14 +44,14 @@ ], [ "content-length", - "323" + "324" ], [ "content-type", "text/plain" ] ], - "body": "eyJuYW1lIjoiZm9vIiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W3sibmFtZSI6ImJhciIsInJlcSI6Ij4gMCIsImZlYXR1cmVzIjpbXSwib3B0aW9uYWwiOmZhbHNlLCJkZWZhdWx0X2ZlYXR1cmVzIjp0cnVlLCJ0YXJnZXQiOm51bGwsImtpbmQiOiJub3JtYWwifV0sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7Im9sZF9mZWF0IjpbXX0sImZlYXR1cmVzMiI6eyJuZXdfZmVhdCI6WyJkZXA6YmFyIiwiYmFyPy9mZWF0Il19LCJ5YW5rZWQiOmZhbHNlLCJ2IjoyfQo=" + "body": "eyJuYW1lIjoiZm9vIiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W3sibmFtZSI6ImJhciIsInJlcSI6Ij4gMCIsImZlYXR1cmVzIjpbXSwib3B0aW9uYWwiOmZhbHNlLCJkZWZhdWx0X2ZlYXR1cmVzIjp0cnVlLCJ0YXJnZXQiOm51bGwsImtpbmQiOiJub3JtYWwifV0sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7fSwiZmVhdHVyZXMyIjp7Im5ld19mZWF0IjpbImRlcDpiYXIiLCJiYXI/L2ZlYXQiXSwib2xkX2ZlYXQiOltdfSwieWFua2VkIjpmYWxzZSwidiI6Mn0K" }, "response": { "status": 200, diff --git a/src/tests/krate/publish.rs b/src/tests/krate/publish.rs index e73212251fc..721e3f93e14 100644 --- a/src/tests/krate/publish.rs +++ b/src/tests/krate/publish.rs @@ -987,11 +987,13 @@ fn features_version_2() { assert_eq!(crates[0].name, "foo"); assert_eq!(crates[0].deps.len(), 1); assert_eq!(crates[0].v, Some(2)); - let features = BTreeMap::from_iter([("old_feat".to_string(), vec![])]); - assert_eq!(crates[0].features, features); - let features2 = BTreeMap::from_iter([( - "new_feat".to_string(), - vec!["dep:bar".to_string(), "bar?/feat".to_string()], - )]); + assert_eq!(crates[0].features, BTreeMap::new()); + let features2 = BTreeMap::from_iter([ + ( + "new_feat".to_string(), + vec!["dep:bar".to_string(), "bar?/feat".to_string()], + ), + ("old_feat".to_string(), vec![]), + ]); assert_eq!(crates[0].features2, Some(features2)); }