File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,14 +130,28 @@ def get_ort_project_type(project):
130130 return "docker"
131131
132132
133+ def sanitize_id_part (value ):
134+ """
135+ Sanitize an identifier part by replacing colons with underscores.
136+ ORT uses colons as separators in the identifier string representation.
137+ """
138+ if value :
139+ return value .replace (":" , "_" )
140+ return value
141+
142+
133143def to_ort_package_list_yml (project ):
134144 """Convert a project object into a YAML string in the ORT package list format."""
135145 project_type = get_ort_project_type (project )
136146
137147 dependencies = []
138148 for package in project .discoveredpackages .all ():
149+ type_ = sanitize_id_part (project_type or package .type )
150+ name = sanitize_id_part (package .name )
151+ version = sanitize_id_part (package .version )
152+
139153 dependency = Dependency (
140- id = f"{ project_type or package . type } ::{ package . name } :{ package . version } " ,
154+ id = f"{ type_ } ::{ name } :{ version } " ,
141155 purl = package .purl ,
142156 sourceArtifact = SourceArtifact (url = package .download_url ),
143157 declaredLicenses = [package .get_declared_license_expression_spdx ()],
Original file line number Diff line number Diff line change @@ -72,3 +72,21 @@ def test_scanpipe_ort_pipes_to_ort_package_list_yml(self):
7272 ],
7373 }
7474 self .assertEqual (expected , package_list )
75+
76+ def test_scanpipe_ort_pipes_to_ort_package_list_yml_sanitization (self ):
77+ project = make_project (name = "Analysis" )
78+ package_data = {
79+ "name" : "passwd" ,
80+ "type" : "deb" ,
81+ "version" : "1:4.13+dfsg1-4ubuntu3.2" ,
82+ "purl" : "pkg:deb/ubuntu/passwd@1:4.13%2Bdfsg1-4ubuntu3.2?arch=amd64" ,
83+ }
84+ pipes .update_or_create_package (project , package_data )
85+
86+ package_list_yml = ort .to_ort_package_list_yml (project )
87+ package_list = saneyaml .load (package_list_yml )
88+ dependency_id = package_list ["dependencies" ][0 ]["id" ]
89+
90+ # The colon in the version should be sanitized
91+ self .assertNotIn ("1:4.13" , dependency_id )
92+ self .assertEqual ("deb::passwd:1_4.13+dfsg1-4ubuntu3.2" , dependency_id )
You can’t perform that action at this time.
0 commit comments