File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,9 +31,10 @@ func (s *Secret) UnmarshalFlag(value string) error {
3131 return fmt .Errorf ("failed to read secret file %s: %w" ,
3232 filePath , err )
3333 }
34- // Trim trailing newlines. Trim both \r and \n to handle
35- // files created on Windows (CRLF) or Unix (LF).
36- * s = Secret (strings .TrimRight (string (content ), "\r \n " ))
34+ // Trim trailing whitespace (spaces, tabs, newlines) to handle
35+ // files created on Windows (CRLF) or Unix (LF), and to avoid
36+ // invisible trailing spaces causing authentication failures.
37+ * s = Secret (strings .TrimRight (string (content ), " \t \r \n " ))
3738
3839 return nil
3940 }
Original file line number Diff line number Diff line change @@ -74,6 +74,20 @@ func TestSecretUnmarshalFlag(t *testing.T) {
7474 require .Equal (t , Secret ("secretpassword" ), s )
7575 })
7676
77+ t .Run ("file with trailing whitespace" , func (t * testing.T ) {
78+ t .Parallel ()
79+
80+ tmpDir := t .TempDir ()
81+ passFile := filepath .Join (tmpDir , "password.txt" )
82+ err := os .WriteFile (passFile , []byte ("secretpassword \t \n " ), 0600 )
83+ require .NoError (t , err )
84+
85+ var s Secret
86+ err = s .UnmarshalFlag ("@" + passFile )
87+ require .NoError (t , err )
88+ require .Equal (t , Secret ("secretpassword" ), s )
89+ })
90+
7791 t .Run ("empty file" , func (t * testing.T ) {
7892 t .Parallel ()
7993
You can’t perform that action at this time.
0 commit comments