Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow angle brackets in DOI validation (#513) #514

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading