Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tagfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import (
)

var (
reColonSpacing = regexp.MustCompile(`\s*:\s*`)
reSpecialChars = regexp.MustCompile(`[^a-z0-9:,+\-]`)
reColonSpacing = regexp.MustCompile(`\s*:\s*`)
reSpecialChars = regexp.MustCompile(`[^a-z0-9:,+\-]`)
reConsecutiveDash = regexp.MustCompile(`-{2,}`)
)

// NormalizeTag normalizes a tag string for consistent matching.
// Applied to BOTH type and value parts separately.
// Rules: trim whitespace, normalize colon spacing, lowercase, spaces→dashes,
// periods→dashes, and remove special chars (except colon, dash, and comma).
// periods→dashes, remove special chars (except colon, dash, and comma),
// and collapse consecutive dashes into one.
func NormalizeTag(s string) string {
// 1. Trim whitespace
s = strings.TrimSpace(s)
Expand All @@ -50,6 +52,9 @@ func NormalizeTag(s string) string {
// Keep: a-z, 0-9, dash, colon, comma
s = reSpecialChars.ReplaceAllString(s, "")

// 7. Collapse consecutive dashes into one (e.g. "V. Gabriel" → "v--gabriel" → "v-gabriel")
s = reConsecutiveDash.ReplaceAllString(s, "-")

return s
}

Expand Down
5 changes: 5 additions & 0 deletions tagfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func TestNormalizeTag(t *testing.T) {
input: "my-tag:value,other",
want: "my-tag:value,other",
},
{
name: "consecutive dashes collapsed",
input: "V. Gabriel",
want: "v-gabriel",
},
}

for _, tt := range tests {
Expand Down
Loading