mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 08:53:15 +01:00
Merge commit '15379d1' into javascript_parser_fix_author
Signed-off-by: Toure <tdunnon@gmail.com>
This commit is contained in:
commit
94e448a818
@ -27,6 +27,7 @@ type PackageJSON struct {
|
||||
Homepage string `json:"homepage"`
|
||||
Description string `json:"description"`
|
||||
Dependencies map[string]string `json:"dependencies"`
|
||||
Repository Repository `json:"repository"`
|
||||
}
|
||||
|
||||
type Author struct {
|
||||
@ -35,10 +36,17 @@ type Author struct {
|
||||
URL string `json:"url" mapstruct:"url"`
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
Type string `json:"type"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// match example: "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)"
|
||||
// ---> name: "Isaac Z. Schlueter" email: "i@izs.me" url: "http://blog.izs.me"
|
||||
var authorPattern = regexp.MustCompile(`^\s*(?P<name>[^<(]*)(\s+<(?P<email>.*)>)?(\s\((?P<url>.*)\))?\s*$`)
|
||||
|
||||
// This method implements the UnmarshalJSON interface to help normalize
|
||||
// the json structure.
|
||||
func (a *Author) UnmarshalJSON(b []byte) error {
|
||||
var authorStr string
|
||||
var fields map[string]string
|
||||
@ -98,6 +106,7 @@ func parsePackageJSON(_ string, reader io.Reader) ([]pkg.Package, error) {
|
||||
Metadata: pkg.NpmMetadata{
|
||||
Author: p.Author.String(),
|
||||
Homepage: p.Homepage,
|
||||
URL: p.Repository.URL,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ func TestParsePackageJSON(t *testing.T) {
|
||||
Metadata: pkg.NpmMetadata{
|
||||
Author: "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
|
||||
Homepage: "https://docs.npmjs.com/",
|
||||
URL: "https://github.com/npm/cli",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -38,6 +39,7 @@ func TestParsePackageJSON(t *testing.T) {
|
||||
Metadata: pkg.NpmMetadata{
|
||||
Author: "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
|
||||
Homepage: "https://docs.npmjs.com/",
|
||||
URL: "https://github.com/npm/cli",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@ -8,5 +8,9 @@
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/npm/cli"
|
||||
},
|
||||
"license": "Artistic-2.0"
|
||||
}
|
||||
@ -9,4 +9,5 @@ type NpmMetadata struct {
|
||||
License string `mapstructure:"license" json:"license"`
|
||||
Homepage string `mapstructure:"homepage" json:"homepage"`
|
||||
Description string `mapstructure:"description" json:"description"`
|
||||
URL string `mapstructure:"url" json:"url"`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user