Skip to content

Commit

Permalink
fix: bug of parsing package without version in requirements.txt
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Grinberg <zgrinber@redhat.com>
  • Loading branch information
zvigrinberg committed Mar 17, 2024
1 parent aa63f82 commit 757dc29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/providers/python_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
26 changes: 13 additions & 13 deletions test/it/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
//
Expand Down

0 comments on commit 757dc29

Please sign in to comment.