Skip to content

Commit

Permalink
fix: is_valid_doi should return False on invalid input
Browse files Browse the repository at this point in the history
  • Loading branch information
alee committed Dec 5, 2024
1 parent 28f9116 commit 8815e77
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django/library/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

# prefix differs across (dev + staging) and production
DATACITE_PREFIX = settings.DATACITE_PREFIX
DOI_PATTERN = re.compile(f"{DATACITE_PREFIX}/[-._;()/:a-zA-Z0-9]+")

MAX_DATACITE_API_WORKERS = 25

Expand Down Expand Up @@ -99,8 +100,9 @@ def print_console_message(dry_run: bool, interactive: bool):

def is_valid_doi(doi: str) -> bool:
# checks if DOI is formatted like this "00.12345/q2xt-rj46"
pattern = re.compile(f"{DATACITE_PREFIX}/[-._;()/:a-zA-Z0-9]+")
return re.match(pattern, doi)
if doi:
return re.match(DOI_PATTERN, doi)
return False


class DataCiteApi:
Expand Down

0 comments on commit 8815e77

Please sign in to comment.