From 7d2eb83f1578283ec7ccd0638540eab10b489d1e Mon Sep 17 00:00:00 2001 From: groselt Date: Sat, 30 May 2020 18:09:41 +0100 Subject: [PATCH] Unify sanitizing of filenames --- internal/view/log.go | 2 +- internal/view/table_helper.go | 4 ++-- internal/view/yaml.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/view/log.go b/internal/view/log.go index 07f43029..23b08a77 100644 --- a/internal/view/log.go +++ b/internal/view/log.go @@ -306,7 +306,7 @@ func saveData(cluster, name, data string) (string, error) { } now := time.Now().UnixNano() - fName := fmt.Sprintf("%s-%d.log", strings.Replace(name, "/", "-", -1), now) + fName := fmt.Sprintf("%s-%d.log", SanitizeFilename(name), now) path := filepath.Join(dir, fName) mod := os.O_CREATE | os.O_WRONLY diff --git a/internal/view/table_helper.go b/internal/view/table_helper.go index 64d86469..6348966f 100644 --- a/internal/view/table_helper.go +++ b/internal/view/table_helper.go @@ -18,12 +18,12 @@ import ( func computeFilename(cluster, ns, title, path string) (string, error) { now := time.Now().UnixNano() - dir := filepath.Join(config.K9sDumpDir, cluster) + dir := filepath.Join(config.K9sDumpDir, SanitizeFilename(cluster)) if err := ensureDir(dir); err != nil { return "", err } - name := title + "-" + strings.Replace(path, "/", "-", -1) + name := title + "-" + SanitizeFilename(path) if path == "" { name = title } diff --git a/internal/view/yaml.go b/internal/view/yaml.go index 90ff4258..2c00a9c3 100644 --- a/internal/view/yaml.go +++ b/internal/view/yaml.go @@ -61,13 +61,13 @@ func enableRegion(str string) string { } func saveYAML(cluster, name, data string) (string, error) { - dir := filepath.Join(config.K9sDumpDir, cluster) + dir := filepath.Join(config.K9sDumpDir, SanitizeFilename(cluster)) if err := ensureDir(dir); err != nil { return "", err } now := time.Now().UnixNano() - fName := fmt.Sprintf("%s-%d.yml", strings.Replace(name, "/", "-", -1), now) + fName := fmt.Sprintf("%s-%d.yml", SanitizeFilename(name), now) path := filepath.Join(dir, fName) mod := os.O_CREATE | os.O_WRONLY