From fa8357b2054902550f90e7a1cd498f854473b09a Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Tue, 25 Feb 2025 07:05:00 -0600 Subject: [PATCH] Add length checker for tag imports. Changelog-added: additional import sanity checking to avoid db layer errors (ie, max length exceeded). --- core/import.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/import.go b/core/import.go index 7e6aebb..59e2437 100644 --- a/core/import.go +++ b/core/import.go @@ -107,7 +107,18 @@ func (p pinBoardObj) IsUnread() bool { } func (p pinBoardObj) GetTags() []string { - return strings.Split(strings.TrimSpace(p.Tags), " ") + return trimTags(strings.Split(strings.TrimSpace(p.Tags), " ")) +} + +func trimTags(tags []string) []string { + var ret []string + for _, t := range tags { + if len(t) > 50 { + t = t[:50] + } + ret = append(ret, t) + } + return ret } // Especific html object representation, used by Safari and Chrome @@ -161,7 +172,7 @@ func (h htmlObj) IsUnread() bool { } func (h htmlObj) GetTags() []string { - return strings.Split(strings.TrimSpace(h.Tags), ",") + return trimTags(strings.Split(strings.TrimSpace(h.Tags), ",")) } // This adapter struct is used to wrap a slice [n:m] -- 2.45.3