From 34294e057b54fac3c254befa21a9bfeff96fcb8e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 2 Aug 2022 11:36:25 -0700 Subject: [PATCH 1/2] Allow '+' in keywords For example: keywords = ["c++"]. --- src/models/keyword.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/keyword.rs b/src/models/keyword.rs index 9b432d1cd17..c6377c79b03 100644 --- a/src/models/keyword.rs +++ b/src/models/keyword.rs @@ -56,7 +56,7 @@ impl Keyword { Some(c) => c, }; first.is_ascii_alphanumeric() - && chars.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-') + && chars.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-' || c == '+') } pub fn update_crate(conn: &PgConnection, krate: &Crate, keywords: &[&str]) -> QueryResult<()> { From 29bdb8b9689d17aa6ca59c60b054cfd31293f2b3 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 2 Aug 2022 11:49:37 -0700 Subject: [PATCH 2/2] Add good keyword test --- .../http-data/krate_publish_good_keywords | 62 +++++++++++++++++++ src/tests/krate/publish.rs | 12 ++++ 2 files changed, 74 insertions(+) create mode 100644 src/tests/http-data/krate_publish_good_keywords diff --git a/src/tests/http-data/krate_publish_good_keywords b/src/tests/http-data/krate_publish_good_keywords new file mode 100644 index 00000000000..96375065311 --- /dev/null +++ b/src/tests/http-data/krate_publish_good_keywords @@ -0,0 +1,62 @@ +[ + { + "request": { + "uri": "http://alexcrichton-test.s3.amazonaws.com/crates/foo_good_key/foo_good_key-1.0.0.crate", + "method": "PUT", + "headers": [ + [ + "accept", + "*/*" + ], + [ + "accept-encoding", + "gzip" + ], + [ + "content-length", + "35" + ], + [ + "content-type", + "application/gzip" + ] + ], + "body": "H4sIAAAAAAAA/+3AAQEAAACCIP+vbkhQwKsBLq+17wAEAAA=" + }, + "response": { + "status": 200, + "headers": [], + "body": "" + } + }, + { + "request": { + "uri": "http://alexcrichton-test.s3.amazonaws.com/fo/o_/foo_good_key", + "method": "PUT", + "headers": [ + [ + "accept", + "*/*" + ], + [ + "accept-encoding", + "gzip" + ], + [ + "content-length", + "166" + ], + [ + "content-type", + "text/plain" + ] + ], + "body": "eyJuYW1lIjoiZm9vX2dvb2Rfa2V5IiwidmVycyI6IjEuMC4wIiwiZGVwcyI6W10sImNrc3VtIjoiYWNiNTYwNGIxMjZhYzg5NGMxZWIxMWM0NTc1YmYyMDcyZmVhNjEyMzJhODg4ZTQ1Mzc3MGM3OWQ3ZWQ1NjQxOSIsImZlYXR1cmVzIjp7fSwieWFua2VkIjpmYWxzZSwibGlua3MiOm51bGx9Cg==" + }, + "response": { + "status": 200, + "headers": [], + "body": "" + } + } +] diff --git a/src/tests/krate/publish.rs b/src/tests/krate/publish.rs index 94f078cd443..14f71ae882d 100644 --- a/src/tests/krate/publish.rs +++ b/src/tests/krate/publish.rs @@ -710,6 +710,18 @@ fn publish_after_removing_documentation() { assert_eq!(json.krate.documentation, None); } +#[test] +fn good_keywords() { + let (_, _, _, token) = TestApp::full().with_token(); + let crate_to_publish = PublishBuilder::new("foo_good_key") + .keyword("c++") + .keyword("crates-io_index") + .keyword("1password"); + let json = token.publish_crate(crate_to_publish).good(); + assert_eq!(json.krate.name, "foo_good_key"); + assert_eq!(json.krate.max_version, "1.0.0"); +} + #[test] fn bad_keywords() { let (_, _, _, token) = TestApp::full().with_token();