Trim leading and trailing whitespace when setting secrets from stdin#5086
Trim leading and trailing whitespace when setting secrets from stdin#5086
Conversation
pkg/cmd/secret/set/set.go
Outdated
| } | ||
|
|
||
| return body, nil | ||
| return bytes.TrimSpace(body), nil |
There was a problem hiding this comment.
Since we're trying to mitigate a problem that only happens when using stdin, and is caused by stdin being typically followed by a newline character, could we scope the solution to only those conditions?
- Only trim when reading from stdin;
- Only trim a single trailing
\r?\nand nothing else.
I don't know of realistic scenarios in which preserving all surrounding whitespace will be necessary, but I would like us to avoid doing unnecessary undocumented transformations on the user's input. For example, if someone uses --body "..." to pass a value, I don't see why we should ever change a single byte of that value. With the <<<"..." syntax, however, if the shell magically adds a newline then we can compensate for that by stripping it.
There was a problem hiding this comment.
Yup agreed on both points. The location of the current fix is limited to just stdin input so I think that is covered but I will pair it down to just the trailing newline characters.
This PR changes the behavior of the
secret setcommand to trim leading and trailing whitespace from secrets that are input fromstdin. The issue this solves only mentions trailing whitespace but I could not think of a reason to not trim leading whitespace as well.closes #5031