Skip to content

Commit

Permalink
Merge pull request #5074 from plobsing/master
Browse files Browse the repository at this point in the history
Only strip surrounding quotes if there are at least two characters.
  • Loading branch information
k8s-ci-robot committed Mar 31, 2023
2 parents e07b8a5 + 633da99 commit 3b395a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions api/krusty/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,23 @@ metadata:
name: test-k9cc55dfm5
`)
}

func TestDataIsSingleQuote(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
configMapGenerator:
- name: test
literals:
- TEST='
`)

m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(
m, `apiVersion: v1
data:
TEST: ''''
kind: ConfigMap
metadata:
name: test-m8t7bmb6g2
`)
}
2 changes: 1 addition & 1 deletion api/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func parseLiteralSource(source string) (keyName, value string, err error) {
// removeQuotes removes the surrounding quotes from the provided string only if it is surrounded on both sides
// rather than blindly trimming all quotation marks on either side.
func removeQuotes(str string) string {
if len(str) == 0 || str[0] != str[len(str)-1] {
if len(str) < 2 || str[0] != str[len(str)-1] {
return str
}
if str[0] == '"' || str[0] == '\'' {
Expand Down

0 comments on commit 3b395a9

Please sign in to comment.