Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions __tests__/purl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,25 @@ test('purlsMatch matches packages without namespaces', () => {
const b = parsePURL('pkg:npm/[email protected]')
expect(purlsMatch(a, b)).toBe(true)
})

test('purlsMatch is case-insensitive for GitHub Actions', () => {
const a = parsePURL('pkg:githubactions/MyOrg/[email protected]')
const b = parsePURL('pkg:githubactions/myorg/[email protected]')
expect(purlsMatch(a, b)).toBe(true)
})

test('purlsMatch is case-insensitive for scoped npm packages', () => {
const a = parsePURL('pkg:npm/@MyScope/MyPackage')
const b = parsePURL('pkg:npm/@myscope/mypackage')
expect(purlsMatch(a, b)).toBe(true)
})

test('purlsMatch is case-insensitive for GitHub Actions with file paths', () => {
const a = parsePURL(
'pkg:githubactions/MyOrg/MyWorkflows/.github/workflows/general.yml'
)
const b = parsePURL(
'pkg:githubactions/myorg/myworkflows/.github/workflows/general.yml'
)
expect(purlsMatch(a, b)).toBe(true)
})
16 changes: 12 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/purl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ function fullName(purl: PackageURL): string | null {
// namespace/name splits. This handles the case where a PURL like
// 'pkg:npm/%40scope%2Fname' is parsed as {namespace: null, name: '@scope/name'}
// while 'pkg:npm/%40scope/name' is parsed as {namespace: '@scope', name: 'name'}.
//
// The comparison is case-insensitive because most ecosystems and registries
// treat names that way (npm, PyPI, GitHub org/repo names, etc.).
export function purlsMatch(a: PackageURL, b: PackageURL): boolean {
if (a.type !== b.type) {
if (a.type.toLowerCase() !== b.type.toLowerCase()) {
return false
}
return fullName(a) === fullName(b)
return fullName(a)?.toLowerCase() === fullName(b)?.toLowerCase()
}