mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Merge pull request #312 from anchore/omit-empty-packages
Omit empty packages
This commit is contained in:
commit
7bcdafe745
@ -7,6 +7,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/log"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal"
|
"github.com/anchore/syft/internal"
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
@ -172,6 +174,11 @@ func parsePackageJSON(_ string, reader io.Reader) ([]pkg.Package, error) {
|
|||||||
return nil, fmt.Errorf("failed to parse package.json file: %w", err)
|
return nil, fmt.Errorf("failed to parse package.json file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !p.hasNameAndVersionValues() {
|
||||||
|
log.Debug("encountered package.json file without a name and/or version field, ignoring this file")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
licenses, err := licensesFromJSON(p)
|
licenses, err := licensesFromJSON(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse package.json file: %w", err)
|
return nil, fmt.Errorf("failed to parse package.json file: %w", err)
|
||||||
@ -195,3 +202,7 @@ func parsePackageJSON(_ string, reader io.Reader) ([]pkg.Package, error) {
|
|||||||
|
|
||||||
return packages, nil
|
return packages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p PackageJSON) hasNameAndVersionValues() bool {
|
||||||
|
return p.Name != "" && p.Version != ""
|
||||||
|
}
|
||||||
|
|||||||
@ -142,3 +142,20 @@ func TestParsePackageJSON(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParsePackageJSON_Partial(t *testing.T) { // see https://github.com/anchore/syft/issues/311
|
||||||
|
const fixtureFile = "test-fixtures/pkg-json/package-partial.json"
|
||||||
|
fixture, err := os.Open(fixtureFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to open fixture: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual, err := parsePackageJSON("", fixture)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to parse package-lock.json: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if actualCount := len(actual); actualCount != 0 {
|
||||||
|
t.Errorf("no packages should've been returned (but got %d packages)", actualCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"sideEffects": false,
|
||||||
|
"module": "../../esm/fp/isSaturday/index.js",
|
||||||
|
"typings": "../../typings.d.ts"
|
||||||
|
}
|
||||||
@ -24,7 +24,7 @@ func TestRegression212ApkBufferSize(t *testing.T) {
|
|||||||
t.Fatalf("failed to catalog image: %+v", err)
|
t.Fatalf("failed to catalog image: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedPkgs := 57
|
expectedPkgs := 58
|
||||||
actualPkgs := 0
|
actualPkgs := 0
|
||||||
for range catalog.Enumerate(pkg.ApkPkg) {
|
for range catalog.Enumerate(pkg.ApkPkg) {
|
||||||
actualPkgs += 1
|
actualPkgs += 1
|
||||||
|
|||||||
@ -1,2 +1,5 @@
|
|||||||
FROM alpine:latest
|
FROM alpine@sha256:d9a7354e3845ea8466bb00b22224d9116b183e594527fb5b6c3d30bc01a20378
|
||||||
RUN apk add tzdata vim alpine-sdk
|
RUN apk add --no-cache \
|
||||||
|
tzdata=2020f-r0 \
|
||||||
|
vim=8.2.2320-r0 \
|
||||||
|
alpine-sdk=1.0-r0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user