Skip to content

Commit ebbd697

Browse files
committed
Normalize vulnerableVersionRange
1 parent afe2c00 commit ebbd697

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/utils/socket-package-alert.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ export function getCveInfoByAlertsMap(
325325
alertsMap: AlertsByPkgId,
326326
options?: GetCveInfoByPackageOptions | undefined
327327
): CveInfoByPkgId | null {
328-
debugLog('getCveInfoByAlertsMap')
329328
const exclude = {
330329
upgradable: true,
331330
...({ __proto__: null, ...options } as GetCveInfoByPackageOptions).exclude
@@ -352,13 +351,22 @@ export function getCveInfoByAlertsMap(
352351
}
353352
const { firstPatchedVersionIdentifier, vulnerableVersionRange } =
354353
alert.props
355-
debugLog({ firstPatchedVersionIdentifier, vulnerableVersionRange })
356-
infos.push({
357-
firstPatchedVersionIdentifier,
358-
vulnerableVersionRange: new semver.Range(
354+
try {
355+
infos.push({
356+
firstPatchedVersionIdentifier,
357+
vulnerableVersionRange: new semver.Range(
358+
// Replace ', ' in a range like '>= 1.0.0, < 1.8.2' with ' ' so that
359+
// semver.Range will parse it without erroring.
360+
vulnerableVersionRange.replace(/, +/g, ' ')
361+
).format()
362+
})
363+
} catch (e) {
364+
debugLog('getCveInfoByAlertsMap', {
365+
firstPatchedVersionIdentifier,
359366
vulnerableVersionRange
360-
).format()
361-
})
367+
})
368+
debugLog(e)
369+
}
362370
}
363371
}
364372
return infoByPkg

0 commit comments

Comments
 (0)