Skip to content

Commit

Permalink
Fix version parsing in CMakeLists files CycloneDX#1589
Browse files Browse the repository at this point in the history
  • Loading branch information
asztalosdani committed Jan 24, 2025
1 parent e07b12f commit c04ba5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13188,7 +13188,7 @@ export function parseCmakeLikeFile(cmakeListFile, pkgType, options = {}) {
let parentVersion = undefined;
// In case of meson.build we can find the version number after the word version
// thanks to our replaces and splits
const versionIndex = tmpB.findIndex((v) => v === "version");
const versionIndex = tmpB.findIndex((v) => v?.toLowerCase() === "version");
if (versionIndex > -1 && tmpB.length > versionIndex) {
parentVersion = tmpB[versionIndex + 1];
}
Expand Down
9 changes: 9 additions & 0 deletions lib/helpers/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5734,6 +5734,15 @@ test("parseCmakeLikeFile tests", () => {
type: "application",
version: "",
});
retMap = parseCmakeLikeFile("./test/data/cmakes/CMakeLists-version.txt", "generic");
expect(retMap.parentComponent).toEqual({
"bom-ref": "pkg:generic/[email protected]",
group: "",
name: "MyProject",
purl: "pkg:generic/[email protected]",
type: "application",
version: "2.1.3",
});
retMap = parseCmakeLikeFile(
"./test/data/cmakes/CMakeLists-tpl.txt",
"generic",
Expand Down
5 changes: 5 additions & 0 deletions test/data/cmakes/CMakeLists-version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.15)

project(MyProject VERSION 2.1.3)

add_executable(myexample example.cpp)

0 comments on commit c04ba5f

Please sign in to comment.