-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trim leading and trailing whitespace when setting secrets from stdin #5086
Conversation
pkg/cmd/secret/set/set.go
Outdated
@@ -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.TrimSpace(body), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?\n
and 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic.
This PR changes the behavior of the
secret set
command 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