This repository has been archived on 2026-07-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
codespace/internal/workspace/path.go
T
2026-07-02 15:07:54 +08:00

26 lines
689 B
Go

package workspace
import (
"regexp"
"codespace/internal/util"
)
var idPattern = regexp.MustCompile(`^[A-Za-z0-9._-]+$`)
// ValidID reports whether id is a safe workspace identifier: only letters,
// digits, '-', '_', '.' and non-empty. The bare values "." and ".." are
// rejected because they would resolve to the parent or current directory.
func ValidID(id string) bool {
if id == "" || id == "." || id == ".." {
return false
}
return idPattern.MatchString(id)
}
// RootFor returns the absolute workspace root path for the given base root and
// workspace id. The result is filepath-cleaned.
func RootFor(baseRoot, id string) string {
return util.JoinClean(baseRoot, id)
}