Skip to content
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

Only strip surrounding quotes if there are at least two characters. #5074

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ''''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think three single quartation is more correct in this part.
Do you have any problems?

Copy link
Contributor Author

@plobsing plobsing Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think three single quartation is more correct in this part. Do you have any problems?

I believe the YAML 1.2 spec requires four single quote characters to represent this string. To satisfy the overall single-quoted string literal production (c-single-quoted(n,c)), the first quote introduces the literal (token: c-single-quote), the next two quotes act as an escaped single-quote character (token: c-quoted-quote), and the fourth quote terminates the literal (token: c-single-quote).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I understand what happens to this line!

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