Skip to content

Commit 98319e1

Browse files
authored
Merge branch 'master' into known-cpan
2 parents 2cb3c63 + 9ebba8d commit 98319e1

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

.github/workflows/test.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
go-version: [1.21.x, 1.22.x]
7+
go-version: [1.22.x, 1.23.x]
88
os: [ubuntu-latest]
99
runs-on: ${{ matrix.os }}
1010
steps:
1111
- name: Install Go
12-
uses: actions/setup-go@v2
12+
uses: actions/setup-go@v5
1313
with:
1414
go-version: ${{ matrix.go-version }}
1515
- name: Checkout code
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717
- name: Download test data
18-
run: curl -L https://raw.githubusercontent.com/package-url/purl-spec/master/test-suite-data.json -o testdata/test-suite-data.json
18+
# TODO(@shibumi): Remove pinned version and reset to master, once the failing npm test-cases got fixed.
19+
run: curl -L https://raw.githubusercontent.com/package-url/purl-spec/0dd92f26f8bb11956ffdf5e8acfcee71e8560407/test-suite-data.json -o testdata/test-suite-data.json
1920
- name: Test go fmt
2021
run: test -z $(go fmt ./...)
2122
- name: Golangci-lint
22-
uses: golangci/golangci-lint-action@v2
23+
uses: golangci/golangci-lint-action@v6
2324
with:
2425
only-new-issues: true
2526
- name: Test coverage

.golangci.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# individual linter configs go here
2-
linters-settings:
2+
linters-settings: {}
33

44
# default linters are enabled `golangci-lint help linters`
55
linters:
66
disable-all: true
77
enable:
8-
- deadcode
98
- errcheck
109
- gosimple
1110
- govet
1211
- ineffassign
1312
- staticcheck
14-
- structcheck
1513
- typecheck
1614
- unused
17-
- varcheck

packageurl.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ func typeAdjustNamespace(purlType, ns string) string {
566566
TypeDebian,
567567
TypeGithub,
568568
TypeGolang,
569-
TypeNPM,
570569
TypeRPM,
571570
TypeQpkg:
572571
return strings.ToLower(ns)
@@ -586,8 +585,7 @@ func typeAdjustName(purlType, name string, qualifiers Qualifiers) string {
586585
TypeComposer,
587586
TypeDebian,
588587
TypeGithub,
589-
TypeGolang,
590-
TypeNPM:
588+
TypeGolang:
591589
return strings.ToLower(name)
592590
case TypePyPi:
593591
return strings.ToLower(strings.ReplaceAll(name, "_", "-"))
@@ -657,6 +655,24 @@ func validCustomRules(p PackageURL) error {
657655
}
658656
}
659657
}
658+
case TypeCpan:
659+
if p.Namespace != "" {
660+
// The purl refers to a CPAN distribution.
661+
publisher := p.Namespace
662+
if publisher != strings.ToUpper(publisher) {
663+
return errors.New("a cpan distribution namespace must be all uppercase")
664+
}
665+
distName := p.Name
666+
if strings.Contains(distName, "::") {
667+
return errors.New("a cpan distribution name must not contain '::'")
668+
}
669+
} else {
670+
// The purl refers to a CPAN module.
671+
moduleName := p.Name
672+
if strings.Contains(moduleName, "-") {
673+
return errors.New("a cpan module name may not contain dashes")
674+
}
675+
}
660676
case TypeSwift:
661677
if p.Namespace == "" {
662678
return errors.New("namespace is required")

packageurl_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,24 +515,24 @@ func TestNormalize(t *testing.T) {
515515
}, {
516516
name: "known type namespace adjustments",
517517
input: packageurl.PackageURL{
518-
Type: "npm",
518+
Type: "apk",
519519
Namespace: "NaMeSpAcE",
520520
Name: "pkg",
521521
},
522522
want: packageurl.PackageURL{
523-
Type: "npm",
523+
Type: "apk",
524524
Namespace: "namespace",
525525
Name: "pkg",
526526
Qualifiers: packageurl.Qualifiers{},
527527
},
528528
}, {
529529
name: "known type name adjustments",
530530
input: packageurl.PackageURL{
531-
Type: "npm",
531+
Type: "alpm",
532532
Name: "nAmE",
533533
},
534534
want: packageurl.PackageURL{
535-
Type: "npm",
535+
Type: "alpm",
536536
Name: "name",
537537
Qualifiers: packageurl.Qualifiers{},
538538
},

0 commit comments

Comments
 (0)