Skip to content

Commit

Permalink
updater/portage: trim whitespace for metadata.xml values
Browse files Browse the repository at this point in the history
Closes: https://bugs.gentoo.org/938339
Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Aug 24, 2024
1 parent 55e00fe commit 86e4771
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 8 additions & 7 deletions pkg/portage/repository/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"soko/pkg/config"
"soko/pkg/database"
"soko/pkg/models"
"soko/pkg/utils"
"strings"
)

Expand Down Expand Up @@ -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{
Expand Down
15 changes: 13 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
@@ -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++ {
Expand All @@ -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
}

0 comments on commit 86e4771

Please sign in to comment.