From 6d53d7f421b5aa8396c99bd723b8bc0a64fee378 Mon Sep 17 00:00:00 2001 From: knqyf263 Date: Wed, 29 Mar 2023 18:06:19 +0300 Subject: [PATCH] fix composer --- .../language/php/composer/composer.go | 6 +- .../language/php/composer/composer_test.go | 70 ++++++++++++------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/pkg/fanal/analyzer/language/php/composer/composer.go b/pkg/fanal/analyzer/language/php/composer/composer.go index 1aec56ef694e..9ecb9ac7ef99 100644 --- a/pkg/fanal/analyzer/language/php/composer/composer.go +++ b/pkg/fanal/analyzer/language/php/composer/composer.go @@ -100,11 +100,7 @@ func (a composerAnalyzer) Version() int { } func (a composerAnalyzer) parseComposerLock(path string, r dio.ReadSeekerAt) (*types.Application, error) { - libs, deps, err := a.lockParser.Parse(r) - if err != nil { - return nil, xerrors.Errorf("unable to parse composer.lock: %w", err) - } - return language.ToApplication(types.Composer, path, "", libs, deps), nil + return language.Parse(types.Composer, path, r, a.lockParser) } func (a composerAnalyzer) mergeComposerJson(fsys fs.FS, dir string, app *types.Application) error { diff --git a/pkg/fanal/analyzer/language/php/composer/composer_test.go b/pkg/fanal/analyzer/language/php/composer/composer_test.go index 337bcb0a716e..6511c1cf994d 100644 --- a/pkg/fanal/analyzer/language/php/composer/composer_test.go +++ b/pkg/fanal/analyzer/language/php/composer/composer_test.go @@ -27,21 +27,31 @@ func Test_composerAnalyzer_PostAnalyze(t *testing.T) { FilePath: "composer.lock", Libraries: []types.Package{ { - ID: "pear/log@1.13.3", - Name: "pear/log", - Version: "1.13.3", - Indirect: false, - Licenses: []string{"MIT"}, - Locations: []types.Location{{StartLine: 9, EndLine: 68}}, + ID: "pear/log@1.13.3", + Name: "pear/log", + Version: "1.13.3", + Indirect: false, + Licenses: []string{"MIT"}, + Locations: []types.Location{ + { + StartLine: 9, + EndLine: 68, + }, + }, DependsOn: []string{"pear/pear_exception@v1.0.2"}, }, { - ID: "pear/pear_exception@v1.0.2", - Name: "pear/pear_exception", - Version: "v1.0.2", - Indirect: true, - Licenses: []string{"BSD-2-Clause"}, - Locations: []types.Location{{StartLine: 69, EndLine: 127}}, + ID: "pear/pear_exception@v1.0.2", + Name: "pear/pear_exception", + Version: "v1.0.2", + Indirect: true, + Licenses: []string{"BSD-2-Clause"}, + Locations: []types.Location{ + { + StartLine: 69, + EndLine: 127, + }, + }, }, }, }, @@ -58,21 +68,31 @@ func Test_composerAnalyzer_PostAnalyze(t *testing.T) { FilePath: "composer.lock", Libraries: []types.Package{ { - ID: "pear/log@1.13.3", - Name: "pear/log", - Version: "1.13.3", - Indirect: false, - Licenses: []string{"MIT"}, - Locations: []types.Location{{StartLine: 9, EndLine: 68}}, + ID: "pear/log@1.13.3", + Name: "pear/log", + Version: "1.13.3", + Indirect: false, + Licenses: []string{"MIT"}, + Locations: []types.Location{ + { + StartLine: 9, + EndLine: 68, + }, + }, DependsOn: []string{"pear/pear_exception@v1.0.2"}, }, { - ID: "pear/pear_exception@v1.0.2", - Name: "pear/pear_exception", - Version: "v1.0.2", - Indirect: false, - Licenses: []string{"BSD-2-Clause"}, - Locations: []types.Location{{StartLine: 69, EndLine: 127}}, + ID: "pear/pear_exception@v1.0.2", + Name: "pear/pear_exception", + Version: "v1.0.2", + Indirect: false, + Licenses: []string{"BSD-2-Clause"}, + Locations: []types.Location{ + { + StartLine: 69, + EndLine: 127, + }, + }, }, }, }, @@ -82,7 +102,7 @@ func Test_composerAnalyzer_PostAnalyze(t *testing.T) { { name: "broken composer.lock", dir: "testdata/sad", - wantErr: "unable to parse composer.lock", + wantErr: "failed to parse composer.lock", }, }