From 3f65bd14ccdcf0a4fe29954a931fccf314612d81 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 21 Feb 2024 13:03:41 -0600 Subject: [PATCH] fix: ignore surronding whitespace for cli config (#12250) * fix: ignore surronding whitespace for cli config Cli config files break if you edit them manually with any editor. Editors drop a newline at the end, and we not break on this. If a developer manually edits a file, it should still work --- cli/config/file.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/config/file.go b/cli/config/file.go index 9d8b8b34a0..908af1aac8 100644 --- a/cli/config/file.go +++ b/cli/config/file.go @@ -4,6 +4,7 @@ import ( "io" "os" "path/filepath" + "strings" "github.com/kirsle/configdir" "golang.org/x/xerrors" @@ -85,13 +86,14 @@ func (f File) Write(s string) error { return write(string(f), 0o600, []byte(s)) } -// Read reads the file to a string. +// Read reads the file to a string. All leading and trailing whitespace +// is removed. func (f File) Read() (string, error) { if f == "" { return "", xerrors.Errorf("empty file path") } byt, err := read(string(f)) - return string(byt), err + return strings.TrimSpace(string(byt)), err } // open opens a file in the configuration directory,