Bugfix: Add Trimspace to New Objects (#6226)

This commit is contained in:
Gykes 2025-11-26 14:48:56 -06:00 committed by GitHub
parent a8bb9ae4d3
commit 0bd78f4b62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 75 additions and 38 deletions

View file

@ -98,7 +98,7 @@ func (t changesetTranslator) string(value *string) string {
return "" return ""
} }
return *value return strings.TrimSpace(*value)
} }
func (t changesetTranslator) optionalString(value *string, field string) models.OptionalString { func (t changesetTranslator) optionalString(value *string, field string) models.OptionalString {
@ -106,7 +106,12 @@ func (t changesetTranslator) optionalString(value *string, field string) models.
return models.OptionalString{} return models.OptionalString{}
} }
return models.NewOptionalStringPtr(value) if value == nil {
return models.NewOptionalStringPtr(nil)
}
trimmed := strings.TrimSpace(*value)
return models.NewOptionalString(trimmed)
} }
func (t changesetTranslator) optionalDate(value *string, field string) (models.OptionalDate, error) { func (t changesetTranslator) optionalDate(value *string, field string) (models.OptionalDate, error) {
@ -318,8 +323,14 @@ func (t changesetTranslator) updateStrings(value []string, field string) *models
return nil return nil
} }
// Trim whitespace from each string
trimmedValues := make([]string, len(value))
for i, v := range value {
trimmedValues[i] = strings.TrimSpace(v)
}
return &models.UpdateStrings{ return &models.UpdateStrings{
Values: value, Values: trimmedValues,
Mode: models.RelationshipUpdateModeSet, Mode: models.RelationshipUpdateModeSet,
} }
} }
@ -329,8 +340,14 @@ func (t changesetTranslator) updateStringsBulk(value *BulkUpdateStrings, field s
return nil return nil
} }
// Trim whitespace from each string
trimmedValues := make([]string, len(value.Values))
for i, v := range value.Values {
trimmedValues[i] = strings.TrimSpace(v)
}
return &models.UpdateStrings{ return &models.UpdateStrings{
Values: value.Values, Values: trimmedValues,
Mode: value.Mode, Mode: value.Mode,
} }
} }
@ -448,7 +465,7 @@ func groupsDescriptionsFromGroupInput(input []*GroupDescriptionInput) ([]models.
GroupID: gID, GroupID: gID,
} }
if v.Description != nil { if v.Description != nil {
ret[i].Description = *v.Description ret[i].Description = strings.TrimSpace(*v.Description)
} }
} }

View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
"strings"
"github.com/stashapp/stash/internal/manager" "github.com/stashapp/stash/internal/manager"
"github.com/stashapp/stash/pkg/file" "github.com/stashapp/stash/pkg/file"
@ -43,7 +44,7 @@ func (r *mutationResolver) GalleryCreate(ctx context.Context, input GalleryCreat
// Populate a new gallery from the input // Populate a new gallery from the input
newGallery := models.NewGallery() newGallery := models.NewGallery()
newGallery.Title = input.Title newGallery.Title = strings.TrimSpace(input.Title)
newGallery.Code = translator.string(input.Code) newGallery.Code = translator.string(input.Code)
newGallery.Details = translator.string(input.Details) newGallery.Details = translator.string(input.Details)
newGallery.Photographer = translator.string(input.Photographer) newGallery.Photographer = translator.string(input.Photographer)
@ -74,9 +75,9 @@ func (r *mutationResolver) GalleryCreate(ctx context.Context, input GalleryCreat
} }
if input.Urls != nil { if input.Urls != nil {
newGallery.URLs = models.NewRelatedStrings(input.Urls) newGallery.URLs = models.NewRelatedStrings(stringslice.TrimSpace(input.Urls))
} else if input.URL != nil { } else if input.URL != nil {
newGallery.URLs = models.NewRelatedStrings([]string{*input.URL}) newGallery.URLs = models.NewRelatedStrings([]string{strings.TrimSpace(*input.URL)})
} }
// Start the transaction and save the gallery // Start the transaction and save the gallery

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/stashapp/stash/internal/static" "github.com/stashapp/stash/internal/static"
"github.com/stashapp/stash/pkg/group" "github.com/stashapp/stash/pkg/group"
@ -21,7 +22,7 @@ func groupFromGroupCreateInput(ctx context.Context, input GroupCreateInput) (*mo
// Populate a new group from the input // Populate a new group from the input
newGroup := models.NewGroup() newGroup := models.NewGroup()
newGroup.Name = input.Name newGroup.Name = strings.TrimSpace(input.Name)
newGroup.Aliases = translator.string(input.Aliases) newGroup.Aliases = translator.string(input.Aliases)
newGroup.Duration = input.Duration newGroup.Duration = input.Duration
newGroup.Rating = input.Rating100 newGroup.Rating = input.Rating100
@ -55,7 +56,7 @@ func groupFromGroupCreateInput(ctx context.Context, input GroupCreateInput) (*mo
} }
if input.Urls != nil { if input.Urls != nil {
newGroup.URLs = models.NewRelatedStrings(input.Urls) newGroup.URLs = models.NewRelatedStrings(stringslice.TrimSpace(input.Urls))
} }
return &newGroup, nil return &newGroup, nil

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/stashapp/stash/internal/static" "github.com/stashapp/stash/internal/static"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
@ -32,7 +33,7 @@ func (r *mutationResolver) MovieCreate(ctx context.Context, input MovieCreateInp
// Populate a new group from the input // Populate a new group from the input
newGroup := models.NewGroup() newGroup := models.NewGroup()
newGroup.Name = input.Name newGroup.Name = strings.TrimSpace(input.Name)
newGroup.Aliases = translator.string(input.Aliases) newGroup.Aliases = translator.string(input.Aliases)
newGroup.Duration = input.Duration newGroup.Duration = input.Duration
newGroup.Rating = input.Rating100 newGroup.Rating = input.Rating100
@ -56,9 +57,9 @@ func (r *mutationResolver) MovieCreate(ctx context.Context, input MovieCreateInp
} }
if input.Urls != nil { if input.Urls != nil {
newGroup.URLs = models.NewRelatedStrings(input.Urls) newGroup.URLs = models.NewRelatedStrings(stringslice.TrimSpace(input.Urls))
} else if input.URL != nil { } else if input.URL != nil {
newGroup.URLs = models.NewRelatedStrings([]string{*input.URL}) newGroup.URLs = models.NewRelatedStrings([]string{strings.TrimSpace(*input.URL)})
} }
// Process the base 64 encoded image string // Process the base 64 encoded image string

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/performer" "github.com/stashapp/stash/pkg/performer"
@ -37,9 +38,9 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
// Populate a new performer from the input // Populate a new performer from the input
newPerformer := models.NewPerformer() newPerformer := models.NewPerformer()
newPerformer.Name = input.Name newPerformer.Name = strings.TrimSpace(input.Name)
newPerformer.Disambiguation = translator.string(input.Disambiguation) newPerformer.Disambiguation = translator.string(input.Disambiguation)
newPerformer.Aliases = models.NewRelatedStrings(input.AliasList) newPerformer.Aliases = models.NewRelatedStrings(stringslice.TrimSpace(input.AliasList))
newPerformer.Gender = input.Gender newPerformer.Gender = input.Gender
newPerformer.Ethnicity = translator.string(input.Ethnicity) newPerformer.Ethnicity = translator.string(input.Ethnicity)
newPerformer.Country = translator.string(input.Country) newPerformer.Country = translator.string(input.Country)
@ -62,17 +63,17 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
newPerformer.URLs = models.NewRelatedStrings([]string{}) newPerformer.URLs = models.NewRelatedStrings([]string{})
if input.URL != nil { if input.URL != nil {
newPerformer.URLs.Add(*input.URL) newPerformer.URLs.Add(strings.TrimSpace(*input.URL))
} }
if input.Twitter != nil { if input.Twitter != nil {
newPerformer.URLs.Add(utils.URLFromHandle(*input.Twitter, twitterURL)) newPerformer.URLs.Add(utils.URLFromHandle(strings.TrimSpace(*input.Twitter), twitterURL))
} }
if input.Instagram != nil { if input.Instagram != nil {
newPerformer.URLs.Add(utils.URLFromHandle(*input.Instagram, instagramURL)) newPerformer.URLs.Add(utils.URLFromHandle(strings.TrimSpace(*input.Instagram), instagramURL))
} }
if input.Urls != nil { if input.Urls != nil {
newPerformer.URLs.Add(input.Urls...) newPerformer.URLs.Add(stringslice.TrimSpace(input.Urls)...)
} }
var err error var err error

View file

@ -32,7 +32,7 @@ func (r *mutationResolver) SaveFilter(ctx context.Context, input SaveFilterInput
f := models.SavedFilter{ f := models.SavedFilter{
Mode: input.Mode, Mode: input.Mode,
Name: input.Name, Name: strings.TrimSpace(input.Name),
FindFilter: input.FindFilter, FindFilter: input.FindFilter,
ObjectFilter: input.ObjectFilter, ObjectFilter: input.ObjectFilter,
UIOptions: input.UIOptions, UIOptions: input.UIOptions,

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/stashapp/stash/internal/manager" "github.com/stashapp/stash/internal/manager"
@ -62,9 +63,9 @@ func (r *mutationResolver) SceneCreate(ctx context.Context, input models.SceneCr
} }
if input.Urls != nil { if input.Urls != nil {
newScene.URLs = models.NewRelatedStrings(input.Urls) newScene.URLs = models.NewRelatedStrings(stringslice.TrimSpace(input.Urls))
} else if input.URL != nil { } else if input.URL != nil {
newScene.URLs = models.NewRelatedStrings([]string{*input.URL}) newScene.URLs = models.NewRelatedStrings([]string{strings.TrimSpace(*input.URL)})
} }
newScene.PerformerIDs, err = translator.relatedIds(input.PerformerIds) newScene.PerformerIDs, err = translator.relatedIds(input.PerformerIds)
@ -653,7 +654,7 @@ func (r *mutationResolver) SceneMarkerCreate(ctx context.Context, input SceneMar
// Populate a new scene marker from the input // Populate a new scene marker from the input
newMarker := models.NewSceneMarker() newMarker := models.NewSceneMarker()
newMarker.Title = input.Title newMarker.Title = strings.TrimSpace(input.Title)
newMarker.Seconds = input.Seconds newMarker.Seconds = input.Seconds
newMarker.PrimaryTagID = primaryTagID newMarker.PrimaryTagID = primaryTagID
newMarker.SceneID = sceneID newMarker.SceneID = sceneID

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin/hook" "github.com/stashapp/stash/pkg/plugin/hook"
@ -32,23 +33,23 @@ func (r *mutationResolver) StudioCreate(ctx context.Context, input models.Studio
// Populate a new studio from the input // Populate a new studio from the input
newStudio := models.NewStudio() newStudio := models.NewStudio()
newStudio.Name = input.Name newStudio.Name = strings.TrimSpace(input.Name)
newStudio.Rating = input.Rating100 newStudio.Rating = input.Rating100
newStudio.Favorite = translator.bool(input.Favorite) newStudio.Favorite = translator.bool(input.Favorite)
newStudio.Details = translator.string(input.Details) newStudio.Details = translator.string(input.Details)
newStudio.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag) newStudio.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag)
newStudio.Aliases = models.NewRelatedStrings(input.Aliases) newStudio.Aliases = models.NewRelatedStrings(stringslice.TrimSpace(input.Aliases))
newStudio.StashIDs = models.NewRelatedStashIDs(models.StashIDInputs(input.StashIds).ToStashIDs()) newStudio.StashIDs = models.NewRelatedStashIDs(models.StashIDInputs(input.StashIds).ToStashIDs())
var err error var err error
newStudio.URLs = models.NewRelatedStrings([]string{}) newStudio.URLs = models.NewRelatedStrings([]string{})
if input.URL != nil { if input.URL != nil {
newStudio.URLs.Add(*input.URL) newStudio.URLs.Add(strings.TrimSpace(*input.URL))
} }
if input.Urls != nil { if input.Urls != nil {
newStudio.URLs.Add(input.Urls...) newStudio.URLs.Add(stringslice.TrimSpace(input.Urls)...)
} }
newStudio.ParentID, err = translator.intPtrFromString(input.ParentID) newStudio.ParentID, err = translator.intPtrFromString(input.ParentID)

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
@ -32,9 +33,9 @@ func (r *mutationResolver) TagCreate(ctx context.Context, input TagCreateInput)
// Populate a new tag from the input // Populate a new tag from the input
newTag := models.NewTag() newTag := models.NewTag()
newTag.Name = input.Name newTag.Name = strings.TrimSpace(input.Name)
newTag.SortName = translator.string(input.SortName) newTag.SortName = translator.string(input.SortName)
newTag.Aliases = models.NewRelatedStrings(input.Aliases) newTag.Aliases = models.NewRelatedStrings(stringslice.TrimSpace(input.Aliases))
newTag.Favorite = translator.bool(input.Favorite) newTag.Favorite = translator.bool(input.Favorite)
newTag.Description = translator.string(input.Description) newTag.Description = translator.string(input.Description)
newTag.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag) newTag.IgnoreAutoTag = translator.bool(input.IgnoreAutoTag)

View file

@ -30,7 +30,7 @@ func (ScrapedStudio) IsScrapedContent() {}
func (s *ScrapedStudio) ToStudio(endpoint string, excluded map[string]bool) *Studio { func (s *ScrapedStudio) ToStudio(endpoint string, excluded map[string]bool) *Studio {
// Populate a new studio from the input // Populate a new studio from the input
ret := NewStudio() ret := NewStudio()
ret.Name = s.Name ret.Name = strings.TrimSpace(s.Name)
if s.RemoteSiteID != nil && endpoint != "" { if s.RemoteSiteID != nil && endpoint != "" {
ret.StashIDs = NewRelatedStashIDs([]StashID{ ret.StashIDs = NewRelatedStashIDs([]StashID{
@ -95,37 +95,38 @@ func (s *ScrapedStudio) ToPartial(id string, endpoint string, excluded map[strin
currentTime := time.Now() currentTime := time.Now()
if s.Name != "" && !excluded["name"] { if s.Name != "" && !excluded["name"] {
ret.Name = NewOptionalString(s.Name) ret.Name = NewOptionalString(strings.TrimSpace(s.Name))
} }
if len(s.URLs) > 0 { if len(s.URLs) > 0 {
if !excluded["urls"] { if !excluded["urls"] {
ret.URLs = &UpdateStrings{ ret.URLs = &UpdateStrings{
Values: s.URLs, Values: stringslice.TrimSpace(s.URLs),
Mode: RelationshipUpdateModeSet, Mode: RelationshipUpdateModeSet,
} }
} }
} else { } else {
urls := []string{} urls := []string{}
if s.URL != nil && !excluded["url"] { if s.URL != nil && !excluded["url"] {
urls = append(urls, *s.URL) urls = append(urls, strings.TrimSpace(*s.URL))
} }
if len(urls) > 0 { if len(urls) > 0 {
ret.URLs = &UpdateStrings{ ret.URLs = &UpdateStrings{
Values: urls, Values: stringslice.TrimSpace(urls),
Mode: RelationshipUpdateModeSet, Mode: RelationshipUpdateModeSet,
} }
} }
} }
if s.Details != nil && !excluded["details"] { if s.Details != nil && !excluded["details"] {
ret.Details = NewOptionalString(*s.Details) ret.Details = NewOptionalString(strings.TrimSpace(*s.Details))
} }
if s.Aliases != nil && !excluded["aliases"] { if s.Aliases != nil && !excluded["aliases"] {
ret.Aliases = &UpdateStrings{ ret.Aliases = &UpdateStrings{
Values: stringslice.FromString(*s.Aliases, ","), Values: stringslice.TrimSpace(stringslice.FromString(*s.Aliases, ",")),
Mode: RelationshipUpdateModeSet, Mode: RelationshipUpdateModeSet,
} }
} }
@ -197,10 +198,14 @@ func (ScrapedPerformer) IsScrapedContent() {}
func (p *ScrapedPerformer) ToPerformer(endpoint string, excluded map[string]bool) *Performer { func (p *ScrapedPerformer) ToPerformer(endpoint string, excluded map[string]bool) *Performer {
ret := NewPerformer() ret := NewPerformer()
currentTime := time.Now() currentTime := time.Now()
ret.Name = *p.Name ret.Name = strings.TrimSpace(*p.Name)
if p.Aliases != nil && !excluded["aliases"] { if p.Aliases != nil && !excluded["aliases"] {
ret.Aliases = NewRelatedStrings(stringslice.FromString(*p.Aliases, ",")) aliases := stringslice.FromString(*p.Aliases, ",")
for i, alias := range aliases {
aliases[i] = strings.TrimSpace(alias)
}
ret.Aliases = NewRelatedStrings(aliases)
} }
if p.Birthdate != nil && !excluded["birthdate"] { if p.Birthdate != nil && !excluded["birthdate"] {
date, err := ParseDate(*p.Birthdate) date, err := ParseDate(*p.Birthdate)

View file

@ -44,3 +44,11 @@ func UniqueFold(s []string) []string {
} }
return ret return ret
} }
// TrimSpace trims whitespace from each string in a slice.
func TrimSpace(s []string) []string {
for i, v := range s {
s[i] = strings.TrimSpace(v)
}
return s
}