MCPcopy
hub / github.com/harness/harness / sanitizeReferenceQuery

Function sanitizeReferenceQuery

git/ref.go:243–276  ·  view source on GitHub ↗

sanitizeReferenceQuery removes characters that aren't allowd in a branch name. TODO: should we error out instead of ignore bad chars?

(query string)

Source from the content-addressed store, hash-verified

241// sanitizeReferenceQuery removes characters that aren't allowd in a branch name.
242// TODO: should we error out instead of ignore bad chars?
243func sanitizeReferenceQuery(query string) (string, bool, bool) {
244 if query == "" {
245 return "", false, false
246 }
247
248 // get special characters before anything else
249 matchPrefix := query[0] == '^' // will be removed by mapping
250 matchSuffix := query[len(query)-1] == '$'
251 if matchSuffix {
252 // Special char $ has to be removed manually as it's a valid char
253 // TODO: this restricts the query language to a certain degree, can we do better? (escaping)
254 query = query[:len(query)-1]
255 }
256
257 // strip all unwanted characters
258 return strings.Map(func(r rune) rune {
259 // See https://git-scm.com/docs/git-check-ref-format#_description for more details.
260 switch {
261 // rule 4.
262 case r < 32 || r == 127 || r == ' ' || r == '~' || r == '^' || r == ':':
263 return -1
264
265 // rule 5
266 case r == '?' || r == '*' || r == '[':
267 return -1
268
269 // everything else we map as is
270 default:
271 return r
272 }
273 }, query),
274 matchPrefix,
275 matchSuffix
276}

Callers 1

Calls 1

MapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…