Consolidated a bunch of reused code to agents

This commit is contained in:
2025-03-26 00:21:19 -04:00
parent 5407c1a7cc
commit 5d2c350acf
33 changed files with 2866 additions and 803 deletions

View File

@@ -0,0 +1,23 @@
package console_new
import (
"fmt"
"path/filepath"
"strings"
)
func SafeJoinPath(tempDir, fileName string) (string, error) {
// Clean both paths
tempDir = filepath.Clean(tempDir)
fileName = filepath.Clean(fileName)
// Join paths and clean result
fullPath := filepath.Clean(filepath.Join(tempDir, fileName))
// Verify the path is still within tempDir
if !strings.HasPrefix(fullPath, tempDir+string(filepath.Separator)) {
return "", fmt.Errorf("invalid path")
}
return fullPath, nil
}