SanitizeSearchPath validates a client-supplied search_path so it can be safely embedded in `SET search_path = ' '`. Returns (trimmed, true) when the value is a plausible, injection-safe search_path; ("", false) otherwise (callers should then fall back to the default search_path).
(s string)
| 88 | // when the value is a plausible, injection-safe search_path; ("", false) |
| 89 | // otherwise (callers should then fall back to the default search_path). |
| 90 | func SanitizeSearchPath(s string) (string, bool) { |
| 91 | s = strings.TrimSpace(s) |
| 92 | if s == "" || len(s) > 512 { |
| 93 | return "", false |
| 94 | } |
| 95 | if !safeSearchPathPattern.MatchString(s) { |
| 96 | return "", false |
| 97 | } |
| 98 | return s, true |
| 99 | } |
no outgoing calls