Skip to content

Commit 6b3ae9e

Browse files
committed
be more lenient with doi detection
the specs aren't very strict and especially the resolver does not have to be doi.org at all https://www.doi.org/resources/DOICoreSpecificationv1.pdf
1 parent 5d19724 commit 6b3ae9e

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

lib/galaxy/util/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,5 @@ def to_content_disposition(target: str) -> str:
20292029
def validate_doi(doi: str) -> bool:
20302030
if len(doi) > DOI_MAX_LENGTH:
20312031
return False
2032-
prefix = "https://doi.org/|doi.org/|doi:"
2033-
doi_prefix = r"10\.\d+"
2034-
doi_suffix = r"\S+"
2035-
doi_re = re.compile(f"^{prefix}{doi_prefix}/{doi_suffix}$")
2036-
return bool(doi_re.match(doi))
2032+
doi_re = re.compile(r"(10\.(\d)+\/(.+))")
2033+
return bool(doi_re.search(doi))

test/unit/util/test_utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ class Stuff(str, Enum):
149149
"doi:10.1234567890/42", # longer prefix
150150
"doi:10.1234/42ab:%&*$//crazy-suffix/%/&/",
151151
"doi:10.1234/aa",
152+
"http://doi.org/10.1234/42",
153+
"stillvalid:10.1234/42",
154+
"dx.doi.org:10.1234/42",
155+
"https://dx.doi.org:10.1234/42",
156+
"doi:10.1234/42/a b",
157+
"httpss://dx.doi.org:10.1234/42",
158+
"doi:10.1234/ 42",
152159
]
153160

154161

@@ -158,14 +165,11 @@ def test_validate_doi_pass(input):
158165

159166

160167
DOI_INVALID_VALUES = [
161-
"http://doi.org/10.1234/42",
162-
"invalid:10.1234/42",
163168
"doi:11.1234/42",
164169
"doi:101234/42",
165170
"doi:10. 1234/42",
166171
"doi:10.abc/42",
167-
"doi:10.1234/ 42",
168-
"doi:10.1234/42/a b",
172+
"10.1234 /42/a b",
169173
]
170174

171175

0 commit comments

Comments
 (0)