From 0b8f6dcf9d968dacb4b47e35f2ee4536dfaf07de Mon Sep 17 00:00:00 2001 From: Maximilian Huber Date: Mon, 18 Sep 2023 11:32:38 +0200 Subject: [PATCH] fix(validation): also allow URLs in download locations fix #761 fix #762 Signed-off-by: Maximilian Huber --- src/spdx_tools/spdx/validation/uri_validators.py | 4 ++-- tests/spdx/validation/test_uri_validators.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/spdx_tools/spdx/validation/uri_validators.py b/src/spdx_tools/spdx/validation/uri_validators.py index d3a423732..c14d196f4 100644 --- a/src/spdx_tools/spdx/validation/uri_validators.py +++ b/src/spdx_tools/spdx/validation/uri_validators.py @@ -28,8 +28,8 @@ def validate_url(url: str) -> List[str]: def validate_download_location(location: str) -> List[str]: - if not re.match(download_location_pattern, location): - return [f"must be a valid download location according to the specification, but is: {location}"] + if not (validate_url(location) == [] or re.match(download_location_pattern, location)): + return [f"must be a valid URL or download location according to the specification, but is: {location}"] return [] diff --git a/tests/spdx/validation/test_uri_validators.py b/tests/spdx/validation/test_uri_validators.py index 069cb1b36..2d374ee8e 100644 --- a/tests/spdx/validation/test_uri_validators.py +++ b/tests/spdx/validation/test_uri_validators.py @@ -18,6 +18,8 @@ ) def test_valid_url(input_value): assert validate_url(input_value) == [] + # URLs are also valid download locations: + assert validate_download_location(input_value) == [] # TODO: more negative examples: https://github.com/spdx/tools-python/issues/377 @@ -92,7 +94,7 @@ def test_valid_package_download_location(input_value): ) def test_invalid_package_download_location(input_value): assert validate_download_location(input_value) == [ - f"must be a valid download location according to the specification, but is: {input_value}" + f"must be a valid URL or download location according to the specification, but is: {input_value}" ]