Skip to content

Commit

Permalink
Use cut instead of split when parsing requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
robotdana committed May 12, 2023
1 parent 6452d86 commit 1623b97
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/lockfile/parse-requirements-txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ func parseLine(line string) PackageDetails {
}

if constraint != "" {
splitted := strings.Split(line, constraint)
name = strings.TrimSpace(splitted[0])
unprocessedName, unprocessedVersion, _ := strings.Cut(line, constraint)
name = strings.TrimSpace(unprocessedName)

if constraint != "!=" {
versionWithOptions := strings.TrimSpace(splitted[1])
version = strings.Split(versionWithOptions, " ")[0]
version, _, _ = strings.Cut(strings.TrimSpace(unprocessedVersion), " ")
}
}

Expand All @@ -70,7 +69,7 @@ func normalizedRequirementName(name string) string {
// per https://www.python.org/dev/peps/pep-0503/#normalized-names
name = cachedregexp.MustCompile(`[-_.]+`).ReplaceAllString(name, "-")
name = strings.ToLower(name)
name = strings.Split(name, "[")[0]
name, _, _ = strings.Cut(name, "[")

return name
}
Expand Down

0 comments on commit 1623b97

Please sign in to comment.