From 5a139a680a40a9628cd4c0116226f7c9ae470572 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 2 Dec 2020 10:47:52 -0800 Subject: rust: rename and improve dblp key (id) syntax check --- rust/src/endpoint_handlers.rs | 2 +- rust/src/identifiers.rs | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'rust') diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs index 91ea2393..141c414e 100644 --- a/rust/src/endpoint_handlers.rs +++ b/rust/src/endpoint_handlers.rs @@ -536,7 +536,7 @@ impl Server { Some(dblp), None, ) => { - check_dblp_id(dblp)?; + check_dblp_key(dblp)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = release_rev::table .inner_join(release_ident::table) diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs index 76f978f9..9d766417 100644 --- a/rust/src/identifiers.rs +++ b/rust/src/identifiers.rs @@ -388,15 +388,15 @@ fn test_check_doaj_id() { assert!(check_doaj_id("1b39813549077b2347c0f370c3864b411").is_err()); } -pub fn check_dblp_id(raw: &str) -> Result<()> { +pub fn check_dblp_key(raw: &str) -> Result<()> { lazy_static! { // TODO: what should this actually be? more or less restrictive? - static ref RE: Regex = Regex::new(r"^[a-z]+/[a-zA-Z0-9]+/[a-zA-Z0-9/]+$").unwrap(); + static ref RE: Regex = Regex::new(r"^(journals|conf|series|phd|books|tr|ms|www)(/[a-zA-Z0-9-+]+){1,4}$").unwrap(); } if raw.is_ascii() && RE.is_match(raw) { Ok(()) } else { - Err(FatcatError::MalformedChecksum( + Err(FatcatError::MalformedExternalId( "dblp Article Key (expected, eg, 'journals/entcs/GoubaultM12')".to_string(), raw.to_string(), ))? @@ -404,11 +404,19 @@ pub fn check_dblp_id(raw: &str) -> Result<()> { } #[test] -fn test_check_dblp_id() { - assert!(check_dblp_id("journals/entcs/GoubaultM12").is_ok()); - assert!(check_dblp_id("journals/entcs/GoubaultM12").is_ok()); - assert!(check_dblp_id("10.123*").is_err()); - assert!(check_dblp_id("").is_err()); +fn test_check_dblp_key() { + assert!(check_dblp_key("journals/entcs/GoubaultM12").is_ok()); + assert!(check_dblp_key("journals/entcs/GoubaultM12").is_ok()); + assert!(check_dblp_key("conf/entcs/GoubaultM12").is_ok()); + assert!(check_dblp_key("conf/3dica/DorringtonGCPS11").is_ok()); + assert!(check_dblp_key("conf/c++/CohenHS91").is_ok()); + assert!(check_dblp_key("phd/Hoff2002").is_ok()); + assert!(check_dblp_key("phd/dk/Heine2010").is_ok()); + assert!(check_dblp_key("phd/Beferull-Lozano02").is_ok()); + assert!(check_dblp_key("www/org/w3/TR/xmlquery-use-cases").is_ok()); + assert!(check_dblp_key("books/mc/18/KuznetsovSPCSS18").is_ok()); + assert!(check_dblp_key("10.123*").is_err()); + assert!(check_dblp_key("").is_err()); } pub fn check_oai_id(raw: &str) -> Result<()> { -- cgit v1.2.3