Skip to content

Commit

Permalink
fix: trim quotes in interactive input (#5499) (#5545)
Browse files Browse the repository at this point in the history
This trims quotes (single quotes, double quotes, back quotes) from
interactively added strings.

Closes #5499

Signed-off-by: Ryo Imai <iryo@jp.ibm.com>
  • Loading branch information
ima1mai committed Feb 15, 2022
1 parent 62a5ac9 commit 158da14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/fragments/trim-quotes-input.yaml
@@ -0,0 +1,5 @@
entries:
- description: >
Fixed a bug in `generate kustomze manifest` that quotes from interactive input were not trimmed properly.
kind: bugfix
breaking: false
2 changes: 1 addition & 1 deletion internal/util/projutil/interactive_promt_util.go
Expand Up @@ -90,7 +90,7 @@ func readLine(reader *bufio.Reader) string {
if err != nil {
log.Fatalf("Error when reading input: %v", err)
}
return strings.TrimSpace(text)
return strings.Trim(strings.TrimSpace(text), "`'\"")
}

func readInput(reader *bufio.Reader) string {
Expand Down
8 changes: 8 additions & 0 deletions internal/util/projutil/interactive_promt_util_test.go
Expand Up @@ -47,6 +47,14 @@ func TestUserInput(t *testing.T) {
},
want: "Memcached Operator",
},
{
name: "test when user provides quoted input to the command",
args: args{
msg: "Enter a word: ",
content: []byte("'Memcached Operator'\n"),
},
want: "Memcached Operator",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 158da14

Please sign in to comment.