centralise special path prefix check

This commit is contained in:
sentriz
2023-12-29 19:20:31 +00:00
parent 552aa3afb1
commit b5de0b3b84
3 changed files with 9 additions and 2 deletions
+5
View File
@@ -54,3 +54,8 @@ func First(path ...string) (string, error) {
}
return "", err
}
// HasPrefix checks a path has a prefix, making sure to respect path boundaries. So that /aa & /a does not match, but /a/a & /a does.
func HasPrefix(p, prefix string) bool {
return p == prefix || strings.HasPrefix(p, filepath.Clean(prefix)+string(filepath.Separator))
}