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:
parent
e68aa12564
commit
3be4b9951d
2 changed files with 8 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue