From 793d21f118f983a06c1b208aa5013799107beba9 Mon Sep 17 00:00:00 2001 From: rhigman <73792779+rhigman@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:48:15 +0100 Subject: [PATCH] Allow angle brackets in DOI validation --- CHANGELOG.md | 3 +++ thoth-api/migrations/0.11.7/down.sql | 11 +++++++++++ thoth-api/migrations/0.11.7/up.sql | 11 +++++++++++ thoth-api/src/model/mod.rs | 8 ++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 thoth-api/migrations/0.11.7/down.sql create mode 100644 thoth-api/migrations/0.11.7/up.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 46598362..82d7c3f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Upgrade `actix-session` to v0.8.0 - Upgrade `chrono` to v0.4.31 +### Fixed + - [#513](https://github.com/thoth-pub/thoth/issues/513) - Expand DOI regex to include angle brackets + ## [[0.11.6]](https://github.com/thoth-pub/thoth/releases/tag/v0.11.6) - 2023-09-08 ### Security - Upgrade `chrono` to v0.4.30 diff --git a/thoth-api/migrations/0.11.7/down.sql b/thoth-api/migrations/0.11.7/down.sql new file mode 100644 index 00000000..b9297c0c --- /dev/null +++ b/thoth-api/migrations/0.11.7/down.sql @@ -0,0 +1,11 @@ +ALTER TABLE work DROP CONSTRAINT work_doi_check; +ALTER TABLE work ADD CONSTRAINT work_doi_check + CHECK (doi ~ '^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]\/:a-zA-Z0-9]+$'); + +ALTER TABLE reference DROP CONSTRAINT reference_doi_check; +ALTER TABLE reference ADD CONSTRAINT reference_doi_check + CHECK (doi ~ '^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]\/:a-zA-Z0-9]+$'); + +ALTER TABLE institution DROP CONSTRAINT institution_institution_doi_check; +ALTER TABLE institution ADD CONSTRAINT institution_institution_doi_check + CHECK (institution_doi ~ '^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]\/:a-zA-Z0-9]+$'); diff --git a/thoth-api/migrations/0.11.7/up.sql b/thoth-api/migrations/0.11.7/up.sql new file mode 100644 index 00000000..40680f44 --- /dev/null +++ b/thoth-api/migrations/0.11.7/up.sql @@ -0,0 +1,11 @@ +ALTER TABLE work DROP CONSTRAINT work_doi_check; +ALTER TABLE work ADD CONSTRAINT work_doi_check + CHECK (doi ~ '^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]<>\/:a-zA-Z0-9]+$'); + +ALTER TABLE reference DROP CONSTRAINT reference_doi_check; +ALTER TABLE reference ADD CONSTRAINT reference_doi_check + CHECK (doi ~ '^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]<>\/:a-zA-Z0-9]+$'); + +ALTER TABLE institution DROP CONSTRAINT institution_institution_doi_check; +ALTER TABLE institution ADD CONSTRAINT institution_institution_doi_check + CHECK (institution_doi ~ '^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]<>\/:a-zA-Z0-9]+$'); diff --git a/thoth-api/src/model/mod.rs b/thoth-api/src/model/mod.rs index 1dfda3fd..c0a6aa7a 100644 --- a/thoth-api/src/model/mod.rs +++ b/thoth-api/src/model/mod.rs @@ -46,7 +46,7 @@ pub enum WeightUnit { feature = "backend", derive(DieselNewType, juniper::GraphQLScalarValue), graphql( - description = r#"Digital Object Identifier. Expressed as `^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]\/:a-zA-Z0-9]+$`"# + description = r#"Digital Object Identifier. Expressed as `^https:\/\/doi\.org\/10\.\d{4,9}\/[-._\;\(\)\[\]<>\/:a-zA-Z0-9]+$`"# ) )] #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] @@ -144,7 +144,7 @@ impl FromStr for Doi { // and captures the identifier segment starting with the "10." directory indicator // Corresponds to database constraints although regex syntax differs slightly // (e.g. `;()/` do not need to be escaped here) - r"^(?i:(?:https?://)?(?:www\.)?(?:dx\.)?doi\.org/)?(10\.\d{4,9}/[-._;()\[\]/:a-zA-Z0-9]+$)").unwrap(); + r"^(?i:(?:https?://)?(?:www\.)?(?:dx\.)?doi\.org/)?(10\.\d{4,9}/[-._;()\[\]<>/:a-zA-Z0-9]+$)").unwrap(); } if input.is_empty() { Err(ThothError::DoiEmptyError) @@ -703,6 +703,10 @@ fn test_doi_fromstr() { assert!(Doi::from_str("https://doi-org/10.12345/Test-Suffix.01").is_err()); assert!(Doi::from_str("10.https://doi.org/12345/Test-Suffix.01").is_err()); assert!(Doi::from_str("http://dx.doi.org/10.2990/1471-5457(2005)24[2:tmpwac]2.0.co;2").is_ok()); + assert!(Doi::from_str( + "https://doi.org/10.1002/(SICI)1098-2736(199908)36:6<637::AID-TEA4>3.0.CO;2-9" + ) + .is_ok()); } #[test]