Skip to content

Commit f68153c

Browse files
committed
Fix get_advisory_url to handle string file paths
The function now accepts both Path objects and strings for the `file` and `base_path` parameters, converting strings to Path objects before calling relative_to(). This fixes the AttributeError that occurred when importers passed string paths instead of Path objects. Fixes: #2016 Signed-off-by: Mrityunjay Raj <mr.raj.earth@gmail.com>
1 parent 4171dbe commit f68153c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

vulnerabilities/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import urllib.request
1919
from collections import defaultdict
2020
from functools import total_ordering
21+
from pathlib import Path
2122
from http import HTTPStatus
2223
from typing import List
2324
from typing import Optional
@@ -543,6 +544,10 @@ def get_advisory_url(file, base_path, url):
543544
"""
544545
Return the advisory URL constructed by combining the base URL with the relative file path.
545546
"""
547+
if isinstance(file, str):
548+
file = Path(file)
549+
if isinstance(base_path, str):
550+
base_path = Path(base_path)
546551
relative_path = str(file.relative_to(base_path)).strip("/")
547552
advisory_url = urljoin(url, relative_path)
548553
return advisory_url

0 commit comments

Comments
 (0)