From 8c5cf31866858c6a94619f10bbcb9330ac16eeef Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Mon, 20 Apr 2026 10:56:48 +0800 Subject: [PATCH] fix: collapse consecutive dashes in NormalizeTag "V. Gabriel" normalized to "v--gabriel" because the period converts to a dash (step 5) and the space also converts to a dash (step 4), leaving two consecutive dashes. Add a final step to collapse any run of dashes into a single dash so the output is always "v-gabriel". --- tagfilter.go | 11 ++++++++--- tagfilter_test.go | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tagfilter.go b/tagfilter.go index 0726c16..8b6be03 100644 --- a/tagfilter.go +++ b/tagfilter.go @@ -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) @@ -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 } diff --git a/tagfilter_test.go b/tagfilter_test.go index 4eb05be..a2a7ea6 100644 --- a/tagfilter_test.go +++ b/tagfilter_test.go @@ -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 {