Skip to content

Commit

Permalink
Fix #513
Browse files Browse the repository at this point in the history
  • Loading branch information
ja573 committed Jun 17, 2024
1 parent 75c2ab9 commit 77f85a1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions thoth-api/migrations/v0.12.6/down.sql
Original file line number Diff line number Diff line change
@@ -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]+$');
11 changes: 11 additions & 0 deletions thoth-api/migrations/v0.12.6/up.sql
Original file line number Diff line number Diff line change
@@ -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<>+[\]]+$');
8 changes: 6 additions & 2 deletions thoth-api/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -707,6 +707,10 @@ fn test_doi_fromstr() {
"https://doi.org/10.1002/(SICI)1098-2736(199908)36:6<637::AID-TEA4>3.0.CO;2-9"
)
.is_ok());
assert!(Doi::from_str(
"https://doi.org/10.1002/(sici)1096-8644(1996)23+<91::aid-ajpa4>3.0.co;2-c"
)
.is_ok());
}

#[test]
Expand Down

0 comments on commit 77f85a1

Please sign in to comment.