diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-08-16 09:42:55 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-08-16 09:42:55 -0700 |
commit | b83347388d17dfd58c9f3d123d3d96d050ca6e9b (patch) | |
tree | b07cfd936e1e405e88e5003fcf022e778161dd5c /rust/src/api_helpers.rs | |
parent | 68e847aadc728d63057be5b8d547c851b02a0008 (diff) | |
download | fatcat-b83347388d17dfd58c9f3d123d3d96d050ca6e9b.tar.gz fatcat-b83347388d17dfd58c9f3d123d3d96d050ca6e9b.zip |
ORCIDs can end in X character
Diffstat (limited to 'rust/src/api_helpers.rs')
-rw-r--r-- | rust/src/api_helpers.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs index 489631b3..020aad76 100644 --- a/rust/src/api_helpers.rs +++ b/rust/src/api_helpers.rs @@ -181,7 +181,7 @@ pub fn check_issn(raw: &str) -> Result<()> { pub fn check_orcid(raw: &str) -> Result<()> { lazy_static! { - static ref RE: Regex = Regex::new(r"^\d{4}-\d{4}-\d{4}-\d{4}$").unwrap(); + static ref RE: Regex = Regex::new(r"^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$").unwrap(); } if RE.is_match(raw) { Ok(()) @@ -193,6 +193,14 @@ pub fn check_orcid(raw: &str) -> Result<()> { } } +#[test] +fn test_check_orcid() { + assert!(check_orcid("0123-4567-3456-6789").is_ok()); + assert!(check_orcid("0123-4567-3456-678X").is_ok()); + assert!(check_orcid("01234567-3456-6780").is_err()); + assert!(check_orcid("0x23-4567-3456-6780").is_err()); +} + // TODO: make the above checks "more correct" // TODO: check ISBN-13 // TODO: check hashes (SHA-1, etc) |