Files
silo-server/internal/pathscope/pathscope.go
T

27 lines
553 B
Go
Raw Normal View History

2026-05-22 20:26:11 -04:00
package pathscope
import (
"path/filepath"
"strings"
)
var likeEscaper = strings.NewReplacer(
`\`, `\\`,
`%`, `\%`,
`_`, `\_`,
)
// EscapeLike escapes LIKE wildcards in a literal fragment for use with
// ESCAPE '\' queries.
func EscapeLike(literal string) string {
return likeEscaper.Replace(literal)
}
2026-05-22 20:26:11 -04:00
func PrefixLike(pathPrefix string) string {
clean := filepath.Clean(pathPrefix)
if clean == string(filepath.Separator) {
return likeEscaper.Replace(clean) + "%"
}
return likeEscaper.Replace(clean) + string(filepath.Separator) + "%"
}