Safe standardizes and sanitizes str for use as a single component of a storage key. This method is idempotent.
(str string)
| 267 | // a single component of a storage key. This method |
| 268 | // is idempotent. |
| 269 | func (keys KeyBuilder) Safe(str string) string { |
| 270 | str = strings.ToLower(str) |
| 271 | str = strings.TrimSpace(str) |
| 272 | |
| 273 | // replace a few specific characters |
| 274 | repl := strings.NewReplacer( |
| 275 | " ", "_", |
| 276 | "+", "_plus_", |
| 277 | "*", "wildcard_", |
| 278 | ":", "-", |
| 279 | "..", "", // prevent directory traversal (regex allows single dots) |
| 280 | ) |
| 281 | str = repl.Replace(str) |
| 282 | |
| 283 | // finally remove all non-word characters |
| 284 | return safeKeyRE.ReplaceAllLiteralString(str, "") |
| 285 | } |
| 286 | |
| 287 | // CleanUpOwnLocks immediately cleans up all |
| 288 | // current locks obtained by this process. Since |
no outgoing calls
no test coverage detected