Skip to content

Commit daf44fb

Browse files
authored
improved checksum parsing (#280)
Signed-off-by: Brian DeHamer <[email protected]>
1 parent eda10f8 commit daf44fb

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

__tests__/subject.test.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,22 @@ badline
473473
'187dcd1506a170337415589ff00c8743f19d41cc31fca246c2739dfd450d0b9d'
474474
}
475475
})
476+
expect(subjects).toContainEqual({
477+
name: 'demo_0.0.1_darwin_arm64',
478+
digest: {
479+
sha512:
480+
'5d8b4751ef31f9440d843fcfa4e53ca2e25b1cb1f13fd355fdc7c24b41fe645293291ea9297ba3989078abb77ebbaac66be073618a9e4974dbd0361881d4c718'
481+
}
482+
})
476483
})
477484
})
478485
})
479486

480487
describe('when specifying a subject checksums string', () => {
481488
const checksums = `
482489
f861e68a080799ca83104630b56abb90d8dbcc5f8b5a8639cb691e269838f29e demo_0.0.1_linux_386
483-
187dcd1506a170337415589ff00c8743f19d41cc31fca246c2739dfd450d0b9d demo_0.0.1_linux_amd64
484-
9ecbf449e286a8a8748c161c52aa28b6b2fc64ab86f94161c5d1b3abc18156c5 demo_0.0.1_linux_arm64`
490+
187dcd1506a170337415589ff00c8743f19d41cc31fca246c2739dfd450d0b9d *demo_0.0.1_linux_amd64
491+
9ecbf449e286a8a8748c161c52aa28b6b2fc64ab86f94161c5d1b3abc18156c5 demo_0.0.1_linux_arm64`
485492

486493
it('returns the multiple subjects', async () => {
487494
const inputs: SubjectInputs = {
@@ -500,6 +507,20 @@ f861e68a080799ca83104630b56abb90d8dbcc5f8b5a8639cb691e269838f29e demo_0.0.1_lin
500507
'f861e68a080799ca83104630b56abb90d8dbcc5f8b5a8639cb691e269838f29e'
501508
}
502509
})
510+
expect(subjects).toContainEqual({
511+
name: 'demo_0.0.1_linux_amd64',
512+
digest: {
513+
sha256:
514+
'187dcd1506a170337415589ff00c8743f19d41cc31fca246c2739dfd450d0b9d'
515+
}
516+
})
517+
expect(subjects).toContainEqual({
518+
name: 'demo_0.0.1_linux_arm64',
519+
digest: {
520+
sha256:
521+
'9ecbf449e286a8a8748c161c52aa28b6b2fc64ab86f94161c5d1b3abc18156c5'
522+
}
523+
})
503524
})
504525
})
505526

dist/index.js

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

src/subject.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ const getSubjectFromChecksumsString = (checksums: string): Subject[] => {
181181
continue
182182
}
183183

184-
// Swallow the type identifier character at the beginning of the name
185-
const name = record.slice(delimIndex + 2)
184+
// It's common for checksum records to have a leading flag character before
185+
// the artifact name. It will be either a '*' or a space.
186+
const flag_and_name = record.slice(delimIndex + 1)
187+
const name =
188+
flag_and_name.startsWith('*') || flag_and_name.startsWith(' ')
189+
? flag_and_name.slice(1)
190+
: flag_and_name
191+
186192
const digest = record.slice(0, delimIndex)
187193

188194
if (!HEX_STRING_RE.test(digest)) {

0 commit comments

Comments
 (0)