Skip to content

Commit dea54b4

Browse files
authored
Merge pull request #1057 from actions/juxtin/case-sensitivity
Make purl comparisons case insensitive
2 parents b49f407 + 8cf743c commit dea54b4

4 files changed

Lines changed: 40 additions & 7 deletions

File tree

__tests__/purl.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,25 @@ test('purlsMatch matches packages without namespaces', () => {
225225
const b = parsePURL('pkg:npm/lodash@5.0.0')
226226
expect(purlsMatch(a, b)).toBe(true)
227227
})
228+
229+
test('purlsMatch is case-insensitive for GitHub Actions', () => {
230+
const a = parsePURL('pkg:githubactions/MyOrg/MyAction@1.0.0')
231+
const b = parsePURL('pkg:githubactions/myorg/myaction@1.0.0')
232+
expect(purlsMatch(a, b)).toBe(true)
233+
})
234+
235+
test('purlsMatch is case-insensitive for scoped npm packages', () => {
236+
const a = parsePURL('pkg:npm/@MyScope/MyPackage')
237+
const b = parsePURL('pkg:npm/@myscope/mypackage')
238+
expect(purlsMatch(a, b)).toBe(true)
239+
})
240+
241+
test('purlsMatch is case-insensitive for GitHub Actions with file paths', () => {
242+
const a = parsePURL(
243+
'pkg:githubactions/MyOrg/MyWorkflows/.github/workflows/general.yml'
244+
)
245+
const b = parsePURL(
246+
'pkg:githubactions/myorg/myworkflows/.github/workflows/general.yml'
247+
)
248+
expect(purlsMatch(a, b)).toBe(true)
249+
})

dist/index.js

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/purl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ function fullName(purl: PackageURL): string | null {
8686
// namespace/name splits. This handles the case where a PURL like
8787
// 'pkg:npm/%40scope%2Fname' is parsed as {namespace: null, name: '@scope/name'}
8888
// while 'pkg:npm/%40scope/name' is parsed as {namespace: '@scope', name: 'name'}.
89+
//
90+
// The comparison is case-insensitive because most ecosystems and registries
91+
// treat names that way (npm, PyPI, GitHub org/repo names, etc.).
8992
export function purlsMatch(a: PackageURL, b: PackageURL): boolean {
90-
if (a.type !== b.type) {
93+
if (a.type.toLowerCase() !== b.type.toLowerCase()) {
9194
return false
9295
}
93-
return fullName(a) === fullName(b)
96+
return fullName(a)?.toLowerCase() === fullName(b)?.toLowerCase()
9497
}

0 commit comments

Comments
 (0)