Merge ea4fe334e6c55b55076925c31277f2b2a372b84a into 94eb6c522b63198bdc4565442d86918ad43156e5

This commit is contained in:
Tom Boucher 2026-05-01 12:19:12 -04:00 committed by GitHub
commit b52de87781
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,23 +34,25 @@ type TagConf struct {
SplitRx *regexp.Regexp `yaml:"-"` SplitRx *regexp.Regexp `yaml:"-"`
} }
// SplitTagValue splits a tag value by the split separators, but only if it has a single value. // SplitTagValue splits tag values by the configured split separators.
// Each value in the input slice is individually split and trimmed.
func (c TagConf) SplitTagValue(values []string) []string { func (c TagConf) SplitTagValue(values []string) []string {
// If there's not exactly one value or no separators, return early. if c.SplitRx == nil || len(values) == 0 {
if len(values) != 1 || c.SplitRx == nil {
return values return values
} }
tag := values[0]
var result []string
for _, tag := range values {
// Replace all occurrences of any separator with the zero-width space. // Replace all occurrences of any separator with the zero-width space.
tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp) tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp)
// Split by the zero-width space and trim each substring. // Split by the zero-width space and trim each substring.
parts := strings.Split(tag, consts.Zwsp) parts := strings.Split(tag, consts.Zwsp)
for i, part := range parts { for _, part := range parts {
parts[i] = strings.TrimSpace(part) result = append(result, strings.TrimSpace(part))
} }
return parts }
return result
} }
type TagType string type TagType string