Skip to content

Commit 0ff7f94

Browse files
committed
fix: improve alphanumeric repo conversion
Signed-off-by: Josef Andersson <[email protected]>
1 parent 923ecd9 commit 0ff7f94

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/provider/stringconvert/convert.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import (
1717
)
1818

1919
var (
20-
nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9-]+`)
20+
// Regex to match non-alphanumeric chars, except hyphens between alphanumerics.
21+
22+
doubleHyphenRegex = regexp.MustCompile(`-{2,}`)
23+
nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9-]|^-|-$`)
2124
linebreakReplacer = strings.NewReplacer(
2225
"\r\n", " ", "\r", " ", "\n", " ", "\v", " ",
2326
"\f", " ", "\u0085", " ", "\u2028", " ", "\u2029", " ",
@@ -28,12 +31,14 @@ var (
2831
// except for underscores and hyphens.
2932
func RemoveNonAlphaNumericChars(ctx context.Context, input string) string {
3033
result := nonAlphanumericRegex.ReplaceAllString(input, "")
34+
35+
normalized := doubleHyphenRegex.ReplaceAllString(result, "-")
3136
log.Logger(ctx).Debug().
3237
Str("input", input).
3338
Str("result", result).
3439
Msg("Removed non-alphanumeric characters")
3540

36-
return result
41+
return normalized
3742
}
3843

3944
// RemoveLinebreaks replaces all types of linebreak characters in the input string with a space.

0 commit comments

Comments
 (0)