Skip to content

Commit

Permalink
Merge pull request #514 from thoth-pub/feature/513_further_doi_regex
Browse files Browse the repository at this point in the history
Allow angle brackets in DOI validation (#513)
  • Loading branch information
rhigman authored Sep 21, 2023
2 parents a7bca8a + 3672da5 commit f65bc0c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions thoth-api/migrations/v0.11.7/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.11.7/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 @@ -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]
Expand Down

0 comments on commit f65bc0c

Please sign in to comment.