diff --git a/.golangci.yaml b/.golangci.yaml index d26d1020..8393abee 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -32,6 +32,7 @@ issues: - path: _test\.go linters: - goerr113 + - dupl - path: main.go linters: - gochecknoglobals diff --git a/detector/parsers/fixtures/pip/with-added-support.txt b/detector/parsers/fixtures/pip/with-added-support.txt new file mode 100644 index 00000000..8a65dbb5 --- /dev/null +++ b/detector/parsers/fixtures/pip/with-added-support.txt @@ -0,0 +1,2 @@ +twisted[http2]==20.3.0 + # via scrapy diff --git a/detector/parsers/parse-requirements-txt.go b/detector/parsers/parse-requirements-txt.go index 52311479..288bb751 100644 --- a/detector/parsers/parse-requirements-txt.go +++ b/detector/parsers/parse-requirements-txt.go @@ -45,12 +45,16 @@ func parseLine(line string) PackageDetails { } return PackageDetails{ - Name: name, + Name: cleanupRequirementName(name), Version: version, Ecosystem: PipEcosystem, } } +func cleanupRequirementName(name string) string { + return strings.Split(name, "[")[0] +} + func removeComments(line string) string { var re = regexp.MustCompile(`(^|\s+)#.*$`) diff --git a/detector/parsers/parse-requirements-txt_test.go b/detector/parsers/parse-requirements-txt_test.go index 28a7e2f8..23d0a27d 100644 --- a/detector/parsers/parse-requirements-txt_test.go +++ b/detector/parsers/parse-requirements-txt_test.go @@ -262,3 +262,21 @@ func TestParseRequirementsTxt_FileFormatExample(t *testing.T) { }, }) } + +func TestParseRequirementsTxt_WithAddedSupport(t *testing.T) { + t.Parallel() + + packages, err := parsers.ParseRequirementsTxt("fixtures/pip/with-added-support.txt") + + if err != nil { + t.Errorf("Got unexpected error: %v", err) + } + + expectPackages(t, packages, []parsers.PackageDetails{ + { + Name: "twisted", + Version: "20.3.0", + Ecosystem: parsers.PipEcosystem, + }, + }) +}