Skip to content

Commit 786ffda

Browse files
committed
fix: add missing throws parameter to golang validator
1 parent bb4185a commit 786ffda

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/purl-type.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ module.exports = {
212212
)
213213
},
214214
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#golang
215-
golang(purl) {
215+
golang(purl, throws) {
216216
// Still being lenient here since the standard changes aren't official.
217217
// Pending spec change: https://github.com/package-url/purl-spec/pull/196
218218
const { version } = purl

test/package-url.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,52 @@ describe('PackageURL', function () {
545545
)
546546
})
547547
})
548+
549+
describe('golang', function () {
550+
it('should throw an error for invalid semver version starting with v', function () {
551+
assert.throws(
552+
() =>
553+
new PackageURL(
554+
'golang',
555+
'github.com',
556+
'example/pkg',
557+
'v1.0.invalid'
558+
),
559+
/golang "version" component starting with a "v" must be followed by a valid semver version/
560+
)
561+
})
562+
563+
it('should allow valid semver version starting with v', function () {
564+
assert.doesNotThrow(() => {
565+
new PackageURL(
566+
'golang',
567+
'github.com',
568+
'example/pkg',
569+
'v1.0.0'
570+
)
571+
})
572+
})
573+
574+
it('should allow pseudo-version numbers', function () {
575+
assert.doesNotThrow(() => {
576+
new PackageURL(
577+
'golang',
578+
'github.com/cncf/xds',
579+
'go',
580+
'v0.0.0-20210922020428-25de7278fc84'
581+
)
582+
})
583+
})
584+
585+
it('should allow versions without v prefix', function () {
586+
assert.doesNotThrow(() => {
587+
new PackageURL(
588+
'golang',
589+
'github.com',
590+
'example/pkg',
591+
'abc123'
592+
)
593+
})
594+
})
595+
})
548596
})

0 commit comments

Comments
 (0)