Trim leading and trailing whitespace when setting secrets from stdin (#5086)

* Trim leading and trailing whitespace when setting secrets from stdin

* Only trim newline at end of string
This commit is contained in:
Sam Coe 2022-01-29 09:32:14 +02:00 committed by GitHub
parent e68aa12564
commit 3be4b9951d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package set
import (
"bytes"
"encoding/base64"
"fmt"
"io"
@ -375,7 +376,7 @@ func getBody(opts *SetOptions) ([]byte, error) {
return nil, fmt.Errorf("failed to read from standard input: %w", err)
}
return body, nil
return bytes.TrimRight(body, "\r\n"), nil
}
func mapRepoNamesToIDs(client *api.Client, host, defaultOwner string, repositoryNames []string) ([]int64, error) {

View file

@ -459,6 +459,11 @@ func Test_getBody(t *testing.T) {
want: "a secret",
stdin: "a secret",
},
{
name: "from stdin with trailing newline character",
want: "a secret",
stdin: "a secret\n",
},
}
for _, tt := range tests {
@ -476,7 +481,7 @@ func Test_getBody(t *testing.T) {
})
assert.NoError(t, err)
assert.Equal(t, string(body), tt.want)
assert.Equal(t, tt.want, string(body))
})
}
}