feat: init sproutclaw-web — Go+Gin backend + React frontend
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
25
backend/internal/utils/paths.go
Normal file
25
backend/internal/utils/paths.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IsPathInsideRoot returns true if candidate is inside (or equal to) root.
|
||||
// Both paths are cleaned and compared case-insensitively on Windows.
|
||||
func IsPathInsideRoot(root, candidate string) bool {
|
||||
root = filepath.Clean(root)
|
||||
candidate = filepath.Clean(candidate)
|
||||
// normalize separators
|
||||
root = filepath.ToSlash(root)
|
||||
candidate = filepath.ToSlash(candidate)
|
||||
// case-insensitive on Windows
|
||||
rootLow := strings.ToLower(root)
|
||||
candLow := strings.ToLower(candidate)
|
||||
return candLow == rootLow || strings.HasPrefix(candLow, rootLow+"/")
|
||||
}
|
||||
|
||||
// IsSameResolvedPath compares two paths after cleaning.
|
||||
func IsSameResolvedPath(a, b string) bool {
|
||||
return filepath.Clean(a) == filepath.Clean(b)
|
||||
}
|
||||
Reference in New Issue
Block a user