Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/purl-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ module.exports = {
)
},
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#golang
golang(purl) {
golang(purl, throws) {
// Still being lenient here since the standard changes aren't official.
// Pending spec change: https://github.com/package-url/purl-spec/pull/196
const { version } = purl
Expand Down
48 changes: 48 additions & 0 deletions test/package-url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,52 @@ describe('PackageURL', function () {
)
})
})

describe('golang', function () {
it('should throw an error for invalid semver version starting with v', function () {
assert.throws(
() =>
new PackageURL(
'golang',
'github.com',
'example/pkg',
'v1.0.invalid'
),
/golang "version" component starting with a "v" must be followed by a valid semver version/
)
})

it('should allow valid semver version starting with v', function () {
assert.doesNotThrow(() => {
new PackageURL(
'golang',
'github.com',
'example/pkg',
'v1.0.0'
)
})
})

it('should allow pseudo-version numbers', function () {
assert.doesNotThrow(() => {
new PackageURL(
'golang',
'github.com/cncf/xds',
'go',
'v0.0.0-20210922020428-25de7278fc84'
)
})
})

it('should allow versions without v prefix', function () {
assert.doesNotThrow(() => {
new PackageURL(
'golang',
'github.com',
'example/pkg',
'abc123'
)
})
})
})
})