diff --git a/extractor/filesystem/language/javascript/yarnlock/testdata/no-version.v1.lock b/extractor/filesystem/language/javascript/yarnlock/testdata/no-version.v1.lock new file mode 100644 index 00000000..0f588197 --- /dev/null +++ b/extractor/filesystem/language/javascript/yarnlock/testdata/no-version.v1.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +balanced-match: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== diff --git a/extractor/filesystem/language/javascript/yarnlock/yarnlock-v1_test.go b/extractor/filesystem/language/javascript/yarnlock/yarnlock-v1_test.go index 7ea1d47b..eac5cf77 100644 --- a/extractor/filesystem/language/javascript/yarnlock/yarnlock-v1_test.go +++ b/extractor/filesystem/language/javascript/yarnlock/yarnlock-v1_test.go @@ -50,6 +50,22 @@ func TestExtractor_Extract_v1(t *testing.T) { }, }, }, + { + Name: "package with no version in header", + InputConfig: extracttest.ScanInputMockConfig{ + Path: "testdata/no-version.v1.lock", + }, + WantInventory: []*extractor.Inventory{ + { + Name: "balanced-match", + Version: "1.0.2", + Locations: []string{"testdata/no-version.v1.lock"}, + SourceCode: &extractor.SourceCodeIdentifier{ + Commit: "", + }, + }, + }, + }, { Name: "two packages", InputConfig: extracttest.ScanInputMockConfig{ diff --git a/extractor/filesystem/language/javascript/yarnlock/yarnlock.go b/extractor/filesystem/language/javascript/yarnlock/yarnlock.go index b5abf43a..958d84c2 100644 --- a/extractor/filesystem/language/javascript/yarnlock/yarnlock.go +++ b/extractor/filesystem/language/javascript/yarnlock/yarnlock.go @@ -118,6 +118,7 @@ func groupYarnPackageDescriptions(ctx context.Context, scanner *bufio.Scanner) ( func extractYarnPackageName(header string) string { // Header format: @my-scope/my-first-package@my-scope/my-first-package#commit=hash str := strings.TrimPrefix(header, "\"") + str = strings.TrimSuffix(str, ":") str, _, _ = strings.Cut(str, ",") isScoped := strings.HasPrefix(str, "@")