diff --git a/pkg/cmd/secret/set/set.go b/pkg/cmd/secret/set/set.go index 56d13b210..33874d0a7 100644 --- a/pkg/cmd/secret/set/set.go +++ b/pkg/cmd/secret/set/set.go @@ -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) { diff --git a/pkg/cmd/secret/set/set_test.go b/pkg/cmd/secret/set/set_test.go index 29a2c4758..7843a8b3b 100644 --- a/pkg/cmd/secret/set/set_test.go +++ b/pkg/cmd/secret/set/set_test.go @@ -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)) }) } }