8000 downloadLocation URIs not case sensitive by clabbenius · Pull Request #826 · spdx/tools-python · GitHub
[go: up one dir, main page]

Skip to content

downloadLocation URIs not case sensitive #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/spdx_tools/spdx/validation/uri_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@
"\\/\\/|ftp:\\/\\/)?([\\w\\-.!~*'()%;:&=+$,]+@)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+){0,100}\\.[a-z]{2,5}"
"(:[0-9]{1,5})?(\\/.*)?"
)
url_pattern_ignore_case = re.compile(url_pattern, re.IGNORECASE)

supported_download_repos: str = "(git|hg|svn|bzr)"
git_pattern = "(git\\+git@[a-zA-Z0-9\\.\\-]+:[a-zA-Z0-9/\\\\.@\\-]+)"
bazaar_pattern = "(bzr\\+lp:[a-zA-Z0-9\\.\\-]+)"
download_location_pattern = (
"^(((" + supported_download_repos + "\\+)?" + url_pattern + ")|" + git_pattern + "|" + bazaar_pattern + ")$"
)
compiled_pattern = re.compile(download_location_pattern, re.IGNORECASE)


def validate_url(url: str) -> List[str]:
if not re.match(url_pattern, url):
if not url_pattern_ignore_case.match(url):
return [f"must be a valid URL, but is: {url}"]

return []


def validate_download_location(location: str) -> List[str]:
if not (validate_url(location) == [] or re.match(download_location_pattern, location)):
if not (validate_url(location) == [] or compiled_pattern.match(location)):
return [f"must be a valid URL or download location according to the specification, but is: {location}"]

return []
Expand Down
3 changes: 3 additions & 0 deletions tests/spdx/validation/test_uri_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"https://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82...",
"http://some.url",
"http://ftp.gnu.org/gnu/glibc/glibc-ports-2.15.tar.gz",
"HTTP://SOME.URL",
],
)
def test_valid_url(input_value):
Expand Down Expand Up @@ -79,6 +80,7 @@ def test_invalid_url(input_value):
"bzr+https://bzr.myproject.org/MyProject/trunk@2019",
"bzr+http://bzr.myproject.org/MyProject/trunk@v1.0",
"bzr+https://bzr.myproject.org/MyProject/trunk@2019#src/somefile.c",
"BZR+HTTPS://BZR.MYPROJECT.ORG/MYPROJECT/TRUNK@2019#SRC/SOMEFILE.C",
],
)
def test_valid_package_download_location(input_value):
Expand Down Expand Up @@ -106,6 +108,7 @@ def test_invalid_package_download_location(input_value):
"https://spdx.org/spdxdocs/spdx-tools-v1.2-3F2504E0-4F89-41D3-9A0C-0305E82...",
"h://someweirdtest^?",
"https://some.uri that goes on!?",
"HTtPS://SOME.URI With CAPITALS",
],
)
def test_valid_uri(input_value):
Expand Down
Loading
0