-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: fix parsing of names and namespaces with colons #178
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,3 +330,47 @@ def test_to_dict_custom_empty_value(self): | |
def test_purl_is_hashable(): | ||
s = {PackageURL(name="hashable", type="pypi")} | ||
assert len(s) == 1 | ||
|
||
|
||
def test_colons_in_name_are_handled_correctly() -> None: | ||
p = PackageURL.from_string( | ||
"pkg:nuget/libiconv:%20character%20set%20conversion%[email protected]?package-id=e11a609df352e292" | ||
) | ||
|
||
assert p.type == "nuget" | ||
assert p.namespace is None | ||
assert p.name == "libiconv: character set conversion library" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a real name, seen in the wild? I do not think this would be a valid NuGet name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the name that started me down this nightmare of journey. :) It's a name picked up by syft in a binary component. |
||
assert p.version == "1.9" | ||
assert p.qualifiers == {"package-id": "e11a609df352e292"} | ||
assert p.subpath == None | ||
|
||
assert PackageURL.from_string(p.to_string()).to_string() == p.to_string() | ||
|
||
|
||
def test_colons_in_namespace_are_handled_correctly() -> None: | ||
p = PackageURL.from_string( | ||
"pkg:nuget/an:odd:space/libiconv:%20character%20set%20conversion%[email protected]?package-id=e11a609df352e292" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use actual real life data rather than made up ones? In all cases the colon should be encoded there IMHO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen a |
||
) | ||
|
||
assert p.type == "nuget" | ||
assert p.namespace == "an:odd:space" | ||
assert p.name == "libiconv: character set conversion library" | ||
assert p.version == "1.9" | ||
assert p.qualifiers == {"package-id": "e11a609df352e292"} | ||
assert p.subpath == None | ||
|
||
assert PackageURL.from_string(p.to_string()).to_string() == p.to_string() | ||
|
||
|
||
def test_encoding_stuff_with_colons_correctly() -> None: | ||
p = PackageURL( | ||
type="nuget", | ||
namespace="an:odd:space", | ||
name="libiconv: character set conversion library", | ||
version="1.9", | ||
qualifiers={"package-id": "e11a609df352e292"}, | ||
) | ||
assert ( | ||
p.to_string() | ||
== "pkg:nuget/an:odd:space/libiconv:%20character%20set%20conversion%[email protected]?package-id=e11a609df352e292" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a serious API change, why do you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it was causing things to blow up when trying to de-serialize an SBOM which had PURLs with colons in the name. Given the discussion here: #152 and specifically the comment here: #152 (comment) I think it is reasonable to enable the de-serialization of name and namespaces with
:
in them.