Skip to content

Commit

Permalink
fix: try better url pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnacioHeredia committed Oct 23, 2024
1 parent fa9e67c commit a8ee61f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ai4papi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def validate_conf(conf):
# Validate DOI and URL
# ref: https://stackoverflow.com/a/48524047/18471590
doiPattern = r"^10.\d{4,9}/[-._;()/:A-Z0-9]+$"
urlPattern = r"^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w.-]*)*\/?$"
if (not re.match(doiPattern, d['doi'], re.IGNORECASE)) & (not re.match(urlPattern, d['doi'], re.IGNORECASE)):
urlPattern = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)"
if not (re.match(doiPattern, d['doi'], re.IGNORECASE) or re.match(urlPattern, d['doi'], re.IGNORECASE)):
raise HTTPException(
status_code=400,
detail="Invalid DOI or URL."
Expand Down

0 comments on commit a8ee61f

Please sign in to comment.