From c85cd555982fdc5f8154ddf97b726566c6491962 Mon Sep 17 00:00:00 2001 From: Seednode Date: Tue, 11 Apr 2023 07:19:06 -0500 Subject: [PATCH] Fixed redirect URIs with relative input paths (e.g. ../../test) and --cache enabled --- cmd/files.go | 44 ++++++++++++++++++++++++++++++-------------- cmd/version.go | 2 +- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index 2e051d1..c48e7d4 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -456,7 +456,12 @@ func scanPath(path string, files *Files, filters *Filters, stats *ScanStats, con wg.Done() }() - err = appendPaths(p, files, filters, stats) + path, err := normalizePath(p) + if err != nil { + fmt.Println(err) + } + + err = appendPaths(path, files, filters, stats) if err != nil { fmt.Println(err) } @@ -622,23 +627,34 @@ func pickFile(args []string, filters *Filters, sort string, index *Index) (strin return "", ErrNoImagesFound } +func normalizePath(path string) (string, error) { + path, err := filepath.EvalSymlinks(path) + if err != nil { + return "", err + } + + absolutePath, err := filepath.Abs(path) + if err != nil { + return "", err + } + + return absolutePath, nil +} + func normalizePaths(args []string) ([]string, error) { paths := []string{} fmt.Println("Paths:") for i := 0; i < len(args); i++ { - path, err := filepath.EvalSymlinks(args[i]) + path, err := normalizePath(args[i]) if err != nil { return nil, err } - absolutePath, err := filepath.Abs(path) - if err != nil { - return nil, err - } + pathMatches := (args[i] == path) - hasSupportedFiles, err := pathHasSupportedFiles(absolutePath) + hasSupportedFiles, err := pathHasSupportedFiles(path) if err != nil { return nil, err } @@ -646,20 +662,20 @@ func normalizePaths(args []string) ([]string, error) { var addPath bool = false switch { - case args[i] == absolutePath && hasSupportedFiles: + case pathMatches && hasSupportedFiles: fmt.Printf("%s\n", args[i]) addPath = true - case args[i] != absolutePath && hasSupportedFiles: - fmt.Printf("%s (resolved to %s)\n", args[i], absolutePath) + case !pathMatches && hasSupportedFiles: + fmt.Printf("%s (resolved to %s)\n", args[i], path) addPath = true - case args[i] == absolutePath && !hasSupportedFiles: + case pathMatches && !hasSupportedFiles: fmt.Printf("%s [No supported files found]\n", args[i]) - case args[i] != absolutePath && !hasSupportedFiles: - fmt.Printf("%s (resolved to %s) [No supported files found]\n", args[i], absolutePath) + case !pathMatches && !hasSupportedFiles: + fmt.Printf("%s (resolved to %s) [No supported files found]\n", args[i], path) } if addPath { - paths = append(paths, absolutePath) + paths = append(paths, path) } } diff --git a/cmd/version.go b/cmd/version.go index 6f8bb25..6b088e1 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.39.0" +var Version = "0.40.0" func init() { rootCmd.AddCommand(versionCmd)