Skip to content
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

fix: convert invalid uri regex #71

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
8 changes: 7 additions & 1 deletion capycli/common/capycli_bom_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import pathlib
import uuid
import re
from datetime import datetime
from enum import Enum
from typing import Any, Dict, Iterable, List, Optional, Union
Expand Down Expand Up @@ -355,9 +356,14 @@ def get_ext_ref(comp: Component, type: ExternalReferenceType, comment: str) -> O
@staticmethod
def set_ext_ref(comp: Component, type: ExternalReferenceType, comment: str, value: str,
hash_algo: str = "", hash: str = "") -> None:

if re.search(XsUri._INVALID_URI_REGEX, str(value)):
cleaned_uri = re.sub(XsUri._INVALID_URI_REGEX, ':', str(value))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get this right, XsUri._INVALID_URI_REGEX mainly checks for invalid percent encoding in a URL, so I'm not sure how this would apply to #70. Also, I'm a bit confused why you replace invalid URL parts with a ":" here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gernot-h Try to take a look at the original CycloneDX code of XsUri. They do this check and then throw an exception.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, and I don't yet see how replacing invalid percent encoding by ":" can help here, but I will try to reproduce #70 as you suggested and then debug it on myself. :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated fix available in #72.

else:
cleaned_uri = str(value)
ext_ref = ExternalReference(
reference_type=type,
url=XsUri(value),
url=XsUri(cleaned_uri),
comment=comment)

if hash_algo and hash:
Expand Down
Loading