MCPcopy Create free account
hub / github.com/github/gh-aw / buildSanitizePreservePattern

Function buildSanitizePreservePattern

pkg/stringutil/sanitize.go:134–155  ·  view source on GitHub ↗

buildSanitizePreservePattern builds a regex character class of allowed characters.

(opts *SanitizeOptions)

Source from the content-addressed store, hash-verified

132
133// buildSanitizePreservePattern builds a regex character class of allowed characters.
134func buildSanitizePreservePattern(opts *SanitizeOptions) string {
135 preserveDot := false
136 preserveUnderscore := false
137 for _, char := range opts.PreserveSpecialChars {
138 switch char {
139 case '.':
140 preserveDot = true
141 case '_':
142 preserveUnderscore = true
143 }
144 }
145
146 var preserveChars strings.Builder
147 preserveChars.WriteString("a-z0-9-") // Always preserve alphanumeric and hyphens
148 if preserveDot {
149 preserveChars.WriteRune('.')
150 }
151 if preserveUnderscore {
152 preserveChars.WriteRune('_')
153 }
154 return preserveChars.String()
155}
156
157// applySanitizePattern removes or replaces characters not in the allowed set.
158// When the caller has requested preservation of special chars, unwanted chars are

Callers 2

SanitizeNameFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1