diff --git a/pkg/portage/repository/package.go b/pkg/portage/repository/package.go index a84c2e1..d24c7bf 100644 --- a/pkg/portage/repository/package.go +++ b/pkg/portage/repository/package.go @@ -11,6 +11,7 @@ import ( "soko/pkg/config" "soko/pkg/database" "soko/pkg/models" + "soko/pkg/utils" "strings" ) @@ -125,30 +126,30 @@ func updateModifiedPackage(changedFile string) *models.Package { Name: strings.TrimSpace(maintainer.Name), Type: strings.TrimSpace(maintainer.Type), Email: strings.TrimSpace(maintainer.Email), - Restrict: maintainer.Restrict, + Restrict: strings.TrimSpace(maintainer.Restrict), } } var longDescription string for _, l := range pkgMetadata.LongDescriptionList { if l.Language == "" || l.Language == "en" { - longDescription = l.Content + longDescription = strings.TrimSpace(l.Content) } } remoteIds := make([]models.RemoteId, len(pkgMetadata.Upstream.RemoteIds)) for i, r := range pkgMetadata.Upstream.RemoteIds { remoteIds[i] = models.RemoteId{ - Type: r.Type, - Id: r.Content, + Type: strings.TrimSpace(r.Type), + Id: strings.TrimSpace(r.Content), } } upstream := models.Upstream{ RemoteIds: remoteIds, - Doc: pkgMetadata.Upstream.Doc, - BugsTo: pkgMetadata.Upstream.BugsTo, - Changelog: pkgMetadata.Upstream.Changelog, + Doc: utils.SliceTrimSpaces(pkgMetadata.Upstream.Doc), + BugsTo: utils.SliceTrimSpaces(pkgMetadata.Upstream.BugsTo), + Changelog: utils.SliceTrimSpaces(pkgMetadata.Upstream.Changelog), } return &models.Package{ diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 51e3b6c..a715ff0 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -1,12 +1,15 @@ // SPDX-License-Identifier: GPL-2.0-only package utils -import "sort" +import ( + "sort" + "strings" +) // Deduplicate accepts a slice of strings and returns // a slice which only contains unique items. func Deduplicate(items []string) []string { - if items != nil && len(items) > 1 { + if len(items) > 1 { sort.Strings(items) j := 0 for i := 1; i < len(items); i++ { @@ -25,3 +28,11 @@ func Deduplicate(items []string) []string { return items } } + +func SliceTrimSpaces(items []string) (res []string) { + res = make([]string, len(items)) + for i, item := range items { + res[i] = strings.TrimSpace(item) + } + return res +}