Skip to content

Commit

Permalink
fix: in windows os, golang creates output with newlines of linux anyway
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Grinberg <zgrinber@redhat.com>
  • Loading branch information
zvigrinberg committed Jul 16, 2024
1 parent 47d2464 commit 27b0d2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function requestComponent(provider, data, url, opts = {}, path = '') {

}
} else {
throw new Error(`Got error response from exhort backend - http return code : ${resp.status}, error message => ${await resp.text()}`)
throw new Error(`Got error response from exhort backend - http return code : ${resp.status}, ex-request-id: ${resp.headers.get("ex-request-id")} error message => ${await resp.text()}`)
}

return Promise.resolve(result)
Expand Down
13 changes: 9 additions & 4 deletions src/providers/golang_gomodules.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function extractPackageName(line) {
*/
function getIgnoredDeps(manifest) {
let goMod = fs.readFileSync(manifest).toString().trim()
let lines = goMod.split(EOL);
let lines = goMod.split(getLineSeparatorGolang());
return lines.filter(line => ignoredLine(line)).map(line=> extractPackageName(line)).map(dep => toPurl(dep,/[ ]{1,3}/,undefined))
}

Expand Down Expand Up @@ -235,7 +235,7 @@ function collectAllDepsFromManifest(lines, goMod) {
*/
function performManifestVersionsCheck(rootElementName, goModGraphOutputRows, manifest) {
let goMod = fs.readFileSync(manifest).toString().trim()
let lines = goMod.split(EOL);
let lines = goMod.split(getLineSeparatorGolang());
let comparisonLines = goModGraphOutputRows.filter((line)=> line.startsWith(rootElementName)).map((line)=> getChildVertexFromEdge(line))
let manifestDeps = collectAllDepsFromManifest(lines,goMod)
try {
Expand Down Expand Up @@ -286,7 +286,7 @@ function getSBOM(manifest, opts = {}, includeTransitive) {
let ignoredDeps = getIgnoredDeps(manifest);
let allIgnoredDeps = ignoredDeps.map((dep) => dep.toString())
let sbom = new Sbom();
let rows = goGraphOutput.split(EOL);
let rows = goGraphOutput.split(getLineSeparatorGolang());
let root = getParentVertexFromEdge(rows[0])
let matchManifestVersions = getCustom("MATCH_MANIFEST_VERSIONS","false",opts);
if(matchManifestVersions === "true") {
Expand Down Expand Up @@ -383,7 +383,7 @@ function getFinalPackagesVersionsForModule(rows,manifestPath,goBin) {
execSync(`${handleSpacesInPath(goBin)} mod download`, options)
let finalVersionsForAllModules = execSync(`${handleSpacesInPath(goBin)} list -m all`, options).toString()
let finalVersionModules = new Map()
finalVersionsForAllModules.split(EOL).filter(string => string.trim()!== "")
finalVersionsForAllModules.split(getLineSeparatorGolang()).filter(string => string.trim()!== "")
.filter(string => string.trim().split(" ").length === 2)
.forEach((dependency) => {
let dep = dependency.split(" ")
Expand Down Expand Up @@ -421,6 +421,11 @@ function getPackageName(fullPackage) {
return fullPackage.split("@")[0]
}

function getLineSeparatorGolang() {
let reg = /\n|\r\n/
return reg
}

// /**
// *
// * @param {string} fullPackage - full package with its name and version-
Expand Down

0 comments on commit 27b0d2e

Please sign in to comment.