From 757dc295760ff8f1cc6f8600de99a05f65027686 Mon Sep 17 00:00:00 2001 From: Zvi Grinberg Date: Sun, 17 Mar 2024 15:11:07 +0200 Subject: [PATCH] fix: bug of parsing package without version in requirements.txt Signed-off-by: Zvi Grinberg --- src/providers/python_controller.js | 13 ++++++++++++- test/it/end-to-end.js | 26 +++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/providers/python_controller.js b/src/providers/python_controller.js index 7abc1cf..ac5a1a1 100644 --- a/src/providers/python_controller.js +++ b/src/providers/python_controller.js @@ -297,7 +297,18 @@ function getDependencyVersion(record) { function getDependencyName(depLine) { const regex = /[^\w\s-_.]/g; let endIndex = depLine.search(regex); - return depLine.substring(0,endIndex) ; + let result = depLine.substring(0,endIndex); + // In case package in requirements text only contain package name without version + if(result.trim() === "") { + const regex = /[\w\s-_.]+/g; + if(depLine.match(regex)) { + result = depLine.match(regex)[0] + } + else { + result = depLine + } + } + return result } /** diff --git a/test/it/end-to-end.js b/test/it/end-to-end.js index 9984e5e..8b4d3eb 100644 --- a/test/it/end-to-end.js +++ b/test/it/end-to-end.js @@ -110,13 +110,13 @@ suite('Integration Tests', () => { }); }).beforeAll(() => process.env["EXHORT_DEV_MODE"] = "true"); -// suite('Integration Tests - Developer Test End to End', () => { -// // let opts = { -// // EXHORT_DEV_MODE: "true", -// // EXHORT_SNYK_TOKEN: "ee64316c-a4ba-4ca0-a785-18cb05ed3f25" -// // -// // } -// +suite('Integration Tests - Developer Test End to End', () => { + // let opts = { + // EXHORT_DEV_MODE: "true", + // EXHORT_SNYK_TOKEN: "ee64316c-a4ba-4ca0-a785-18cb05ed3f25" + // + // } + // test(`Stack Analysis json`, async () => { // process.env["EXHORT_DEBUG"]= "true" // process.env["EXHORT_DEV_MODE"]= "true" @@ -131,15 +131,15 @@ suite('Integration Tests', () => { // EXHORT_OSS_INDEX_USER: 'zgrinber@redhat.com', // EXHORT_GO_MVS_LOGIC_ENABLED: 'true' // } -// -// // process.env["EXHORT_PYTHON_VIRTUAL_ENV"] = "true" -// // process.env["EXHORT_PYTHON_INSTALL_BEST_EFFORTS"] = "true" -// // process.env["MATCH_MANIFEST_VERSIONS"] = "false" +// process.env["EXHORT_PYTHON_VIRTUAL_ENV"] = "true" +// process.env["EXHORT_PYTHON_INSTALL_BEST_EFFORTS"] = "true" +// process.env["MATCH_MANIFEST_VERSIONS"] = "false" // // let pomPath = `/tmp/070324/package.json` -// let pomPath = `/tmp/artifact-without-version-or-group/sbom-json-traversor/pom.xml` +// let pomPath = `/tmp/170324/requirements.txt` // // let pomPath = `/home/zgrinber/git/tracing-demos-and-examples/tracing-parent/pom.xml` // let providedDataForStack; -// providedDataForStack = await index.componentAnalysis("pom.xml", fs.readFileSync(pomPath),{} ,pomPath); +// // providedDataForStack = await index.componentAnalysis("requirements.txt", fs.readFileSync(pomPath).toString(),{},pomPath); +// providedDataForStack = await index.stackAnalysis(pomPath); // // console.log(JSON.stringify(providedDataForStack,null , 4)) // // fs.writeFileSync(`/tmp/301123/report.html`,providedDataForStack) //