Skip to content

Commit ad0f98b

Browse files
schlenkMichael Schlenkerjkowalleck
authored
fix: cyclonedx.model.Property.value value is optional (#631)
`cyclonedx.model.Property.value` value is optional, in accordance with the spec. fixes #630 --------- Signed-off-by: Michael Schlenker <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Michael Schlenker <[email protected]> Co-authored-by: Jan Kowalleck <[email protected]>
1 parent f4ac55d commit ad0f98b

16 files changed

+554
-4
lines changed

cyclonedx/model/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ class Property:
845845
Specifies an individual property with a name and value.
846846
"""
847847

848-
def __init__(self, *, name: str, value: str) -> None:
848+
def __init__(self, *, name: str, value: Optional[str] = None) -> None:
849849
self.name = name
850850
self.value = value
851851

@@ -868,7 +868,7 @@ def name(self, name: str) -> None:
868868

869869
@property
870870
@serializable.xml_name('.')
871-
def value(self) -> str:
871+
def value(self) -> Optional[str]:
872872
"""
873873
Value of this Property.
874874
@@ -878,7 +878,7 @@ def value(self) -> str:
878878
return self._value
879879

880880
@value.setter
881-
def value(self, value: str) -> None:
881+
def value(self, value: Optional[str]) -> None:
882882
self._value = value
883883

884884
def __eq__(self, other: object) -> bool:

tests/_data/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,20 @@ def bom_all_same_bomref() -> Tuple[Bom, int]:
11081108
return bom, nr_bomrefs
11091109

11101110

1111+
def get_bom_for_issue_630_empty_property() -> Bom:
1112+
"""regression test for issue #630
1113+
see https://github.com/CycloneDX/cyclonedx-python-lib/issues/630
1114+
"""
1115+
return _make_bom(components={
1116+
Component(
1117+
bom_ref='[email protected]',
1118+
type=ComponentType.LIBRARY,
1119+
name='example',
1120+
version='15.8.0',
1121+
properties=[Property(name='cdx:npm:package:path')]
1122+
)
1123+
})
1124+
11111125
# ---
11121126

11131127

@@ -1147,4 +1161,5 @@ def bom_all_same_bomref() -> Tuple[Bom, int]:
11471161
get_bom_for_issue_497_urls,
11481162
get_bom_for_issue_598_multiple_components_with_purl_qualifiers,
11491163
get_bom_with_component_setuptools_with_v16_fields,
1164+
get_bom_for_issue_630_empty_property,
11501165
}

tests/_data/own/xml/1.6/regression_issue630.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.0" version="1">
3+
<components>
4+
<component type="library">
5+
<name>example</name>
6+
<version>15.8.0</version>
7+
<modified>false</modified>
8+
</component>
9+
</components>
10+
</bom>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<components>
4+
<component type="library" bom-ref="[email protected]">
5+
<name>example</name>
6+
<version>15.8.0</version>
7+
</component>
8+
</components>
9+
</bom>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "[email protected]",
5+
"name": "example",
6+
"type": "library",
7+
"version": "15.8.0"
8+
}
9+
],
10+
"dependencies": [
11+
{
12+
13+
}
14+
],
15+
"metadata": {
16+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
17+
"tools": [
18+
{
19+
"name": "cyclonedx-python-lib",
20+
"vendor": "CycloneDX",
21+
"version": "TESTING"
22+
}
23+
]
24+
},
25+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
26+
"version": 1,
27+
"$schema": "http://cyclonedx.org/schema/bom-1.2b.schema.json",
28+
"bomFormat": "CycloneDX",
29+
"specVersion": "1.2"
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.2" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<vendor>CycloneDX</vendor>
8+
<name>cyclonedx-python-lib</name>
9+
<version>TESTING</version>
10+
</tool>
11+
</tools>
12+
</metadata>
13+
<components>
14+
<component type="library" bom-ref="[email protected]">
15+
<name>example</name>
16+
<version>15.8.0</version>
17+
</component>
18+
</components>
19+
<dependencies>
20+
<dependency ref="[email protected]"/>
21+
</dependencies>
22+
</bom>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "[email protected]",
5+
"name": "example",
6+
"properties": [
7+
{
8+
"name": "cdx:npm:package:path"
9+
}
10+
],
11+
"type": "library",
12+
"version": "15.8.0"
13+
}
14+
],
15+
"dependencies": [
16+
{
17+
18+
}
19+
],
20+
"metadata": {
21+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
22+
"tools": [
23+
{
24+
"name": "cyclonedx-python-lib",
25+
"vendor": "CycloneDX",
26+
"version": "TESTING"
27+
}
28+
]
29+
},
30+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
31+
"version": 1,
32+
"$schema": "http://cyclonedx.org/schema/bom-1.3a.schema.json",
33+
"bomFormat": "CycloneDX",
34+
"specVersion": "1.3"
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.3" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<vendor>CycloneDX</vendor>
8+
<name>cyclonedx-python-lib</name>
9+
<version>TESTING</version>
10+
</tool>
11+
</tools>
12+
</metadata>
13+
<components>
14+
<component type="library" bom-ref="[email protected]">
15+
<name>example</name>
16+
<version>15.8.0</version>
17+
<properties>
18+
<property name="cdx:npm:package:path"/>
19+
</properties>
20+
</component>
21+
</components>
22+
<dependencies>
23+
<dependency ref="[email protected]"/>
24+
</dependencies>
25+
</bom>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "[email protected]",
5+
"name": "example",
6+
"properties": [
7+
{
8+
"name": "cdx:npm:package:path"
9+
}
10+
],
11+
"type": "library",
12+
"version": "15.8.0"
13+
}
14+
],
15+
"dependencies": [
16+
{
17+
18+
}
19+
],
20+
"metadata": {
21+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
22+
"tools": [
23+
{
24+
"externalReferences": [
25+
{
26+
"type": "build-system",
27+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions"
28+
},
29+
{
30+
"type": "distribution",
31+
"url": "https://pypi.org/project/cyclonedx-python-lib/"
32+
},
33+
{
34+
"type": "documentation",
35+
"url": "https://cyclonedx-python-library.readthedocs.io/"
36+
},
37+
{
38+
"type": "issue-tracker",
39+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues"
40+
},
41+
{
42+
"type": "license",
43+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE"
44+
},
45+
{
46+
"type": "release-notes",
47+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md"
48+
},
49+
{
50+
"type": "vcs",
51+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib"
52+
},
53+
{
54+
"type": "website",
55+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/#readme"
56+
}
57+
],
58+
"name": "cyclonedx-python-lib",
59+
"vendor": "CycloneDX",
60+
"version": "TESTING"
61+
}
62+
]
63+
},
64+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
65+
"version": 1,
66+
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
67+
"bomFormat": "CycloneDX",
68+
"specVersion": "1.4"
69+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<vendor>CycloneDX</vendor>
8+
<name>cyclonedx-python-lib</name>
9+
<version>TESTING</version>
10+
<externalReferences>
11+
<reference type="build-system">
12+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/actions</url>
13+
</reference>
14+
<reference type="distribution">
15+
<url>https://pypi.org/project/cyclonedx-python-lib/</url>
16+
</reference>
17+
<reference type="documentation">
18+
<url>https://cyclonedx-python-library.readthedocs.io/</url>
19+
</reference>
20+
<reference type="issue-tracker">
21+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/issues</url>
22+
</reference>
23+
<reference type="license">
24+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE</url>
25+
</reference>
26+
<reference type="release-notes">
27+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md</url>
28+
</reference>
29+
<reference type="vcs">
30+
<url>https://github.com/CycloneDX/cyclonedx-python-lib</url>
31+
</reference>
32+
<reference type="website">
33+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/#readme</url>
34+
</reference>
35+
</externalReferences>
36+
</tool>
37+
</tools>
38+
</metadata>
39+
<components>
40+
<component type="library" bom-ref="[email protected]">
41+
<name>example</name>
42+
<version>15.8.0</version>
43+
<properties>
44+
<property name="cdx:npm:package:path"/>
45+
</properties>
46+
</component>
47+
</components>
48+
<dependencies>
49+
<dependency ref="[email protected]"/>
50+
</dependencies>
51+
</bom>

0 commit comments

Comments
 (0)