Skip to content

Commit

Permalink
Handle missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
banesullivan committed Jan 13, 2025
1 parent 03376a9 commit b6b9f27
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pyosmeta/utils_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def is_doi(archive) -> str | None:


def clean_archive(archive):
"""Clean an archive link to ensure it is a valid URL.
"""Clean an archive link to ensure it is a valid DOI URL.
This utility will attempt to parse the DOI link from the various formats
that are commonly present in review metadata. This utility will handle:
Expand All @@ -184,6 +184,10 @@ def clean_archive(archive):
`https://doi.org/10.1234/zenodo.12345678` using the `python-doi` package.
"""
archive = archive.strip() # Remove leading/trailing whitespace
if not archive:
# If field is empty, return None
return None

Check warning on line 190 in src/pyosmeta/utils_clean.py

View check run for this annotation

Codecov / codecov/patch

src/pyosmeta/utils_clean.py#L190

Added line #L190 was not covered by tests
if archive.startswith("[") and archive.endswith(")"):
# Extract the outermost link
link = archive[archive.rfind("](") + 2 : -1]
Expand All @@ -197,7 +201,7 @@ def clean_archive(archive):
archive = archive.replace("http://", "https://")

Check warning on line 201 in src/pyosmeta/utils_clean.py

View check run for this annotation

Codecov / codecov/patch

src/pyosmeta/utils_clean.py#L201

Added line #L201 was not covered by tests
# Validate that the URL resolves
if not check_url(archive):
raise ValueError(f"Invalid archive URL: {archive}")
raise ValueError(f"Invalid archive URL (not resolving): {archive}")

Check warning on line 204 in src/pyosmeta/utils_clean.py

View check run for this annotation

Codecov / codecov/patch

src/pyosmeta/utils_clean.py#L204

Added line #L204 was not covered by tests
return archive
elif archive.lower() == "n/a":
return None
Expand Down

0 comments on commit b6b9f27

Please sign in to comment.