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

Conversation

plobsing
Copy link
Contributor

@plobsing plobsing commented Mar 3, 2023

Otherwise, a value consisting of a single quote character triggers a panic:

go test krusty/configmaps_test.go
--- FAIL: TestDataIsSingleQuote (0.00s)
panic: runtime error: slice bounds out of range [1:0] [recovered]
	panic: runtime error: slice bounds out of range [1:0]

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 3, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @plobsing!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 3, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @plobsing. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 3, 2023
@koba1t
Copy link
Member

koba1t commented Mar 22, 2023

Hi @plobsing
Thanks for your contribution!

Otherwise, a value consisting of a single quote character triggers a panic:

Could you please describe in detail when this bug occurred?
And, Can you add comments to explain what happens for the code?

I'm waiting for your response!

/triage needs-information
/kind bug

@k8s-ci-robot k8s-ci-robot added triage/needs-information Indicates an issue needs more information in order to work on it. kind/bug Categorizes issue or PR as related to a bug. labels Mar 22, 2023
@plobsing
Copy link
Contributor Author

Hi @plobsing Thanks for your contribution!

Otherwise, a value consisting of a single quote character triggers a panic:

Could you please describe in detail when this bug occurred? And, Can you add comments to explain what happens for the code?

The panic occurs when a configmap value is specified to be the length-1 string '. The testcase added by this PR has an input that triggers this condition; this input can also be used to demonstrate the panic interactively.

cat >kustomization.yaml <<EOF
configMapGenerator:
  - name: test
    literals:
      - TEST='
EOF
kustomize build

Fails with this diagnostic:

panic: runtime error: slice bounds out of range [1:0]

goroutine 1 [running]:
sigs.k8s.io/kustomize/api/kv.removeQuotes(...)
	sigs.k8s.io/kustomize/api/kv/kv.go:194
sigs.k8s.io/kustomize/api/kv.parseLiteralSource({0x140004c2228, 0x6})
	sigs.k8s.io/kustomize/api/kv/kv.go:184 +0x1a0
sigs.k8s.io/kustomize/api/kv.keyValuesFromLiteralSources({0x1400046a380?, 0x1, 0x1?})
	sigs.k8s.io/kustomize/api/kv/kv.go:67 +0xa4
sigs.k8s.io/kustomize/api/kv.(*loader).Load(0x1?, {{0x1400046a380, 0x1, 0x4}, {0x0, 0x0, 0x0}, {0x0, 0x0, 0x0}, ...})
	sigs.k8s.io/kustomize/api/kv/kv.go:49 +0x14c
sigs.k8s.io/kustomize/api/internal/generators.makeValidatedDataMap({0x1010a7f10, 0x140003e0c80}, {0x140004c2240, 0x4}, {{0x1400046a380, 0x1, 0x4}, {0x0, 0x0, 0x0}, ...})
	sigs.k8s.io/kustomize/api/internal/generators/utils.go:41 +0x9c
sigs.k8s.io/kustomize/api/internal/generators.MakeConfigMap({0x1010a7f10, 0x140003e0c80}, 0x14000377248)
	sigs.k8s.io/kustomize/api/internal/generators/configmap.go:36 +0xb4
sigs.k8s.io/kustomize/api/resource.(*Factory).MakeConfigMap(0x14000377238?, {0x1010a7f10?, 0x140003e0c80?}, 0x14000377248)
	sigs.k8s.io/kustomize/api/resource/factory.go:279 +0x38
sigs.k8s.io/kustomize/api/resmap.(*Factory).FromConfigMapArgs(0x140003773a8?, {0x1010a7f10?, 0x140003e0c80?}, {{{0x0, 0x0}, {0x140004c2240, 0x4}, {0x0, 0x0}, {{0x1400046a380, ...}, ...}, ...}})
	sigs.k8s.io/kustomize/api/resmap/factory.go:94 +0x2c
sigs.k8s.io/kustomize/api/internal/builtins.(*ConfigMapGeneratorPlugin).Generate(0x14000388a90)
	sigs.k8s.io/kustomize/api/internal/builtins/ConfigMapGenerator.go:33 +0x104
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).runGenerators(0x1400038e3c0?, 0x140003821c0)
	sigs.k8s.io/kustomize/api/internal/target/kusttarget.go:272 +0x1b4
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget(0x140000ecfa0, 0x14000384928?)
	sigs.k8s.io/kustomize/api/internal/target/kusttarget.go:224 +0x324
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget(0x0?)
	sigs.k8s.io/kustomize/api/internal/target/kusttarget.go:189 +0x110
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap(0x140000ecfa0)
	sigs.k8s.io/kustomize/api/internal/target/kusttarget.go:130 +0x6c
sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap(...)
	sigs.k8s.io/kustomize/api/internal/target/kusttarget.go:121
sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run(0x14000377d58, {0x1010aea10, 0x1016091f8}, {0x100dd61e6, 0x1})
	sigs.k8s.io/kustomize/api/krusty/kustomizer.go:90 +0x244
sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1(0x1400027aa00?, {0x1016091f8?, 0x0?, 0x0?})
	sigs.k8s.io/kustomize/kustomize/v5/commands/build/build.go:82 +0x170
github.com/spf13/cobra.(*Command).execute(0x1400027aa00, {0x1016091f8, 0x0, 0x0})
	github.com/spf13/cobra@v1.4.0/command.go:856 +0x4c4
github.com/spf13/cobra.(*Command).ExecuteC(0x1400027a500)
	github.com/spf13/cobra@v1.4.0/command.go:974 +0x354
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/cobra@v1.4.0/command.go:902
main.main()
	sigs.k8s.io/kustomize/kustomize/v5/main.go:14 +0x20

@KnVerey
Copy link
Contributor

KnVerey commented Mar 27, 2023

/triage accepted
/ok-to-test
/priority important-soon

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 27, 2023
@KnVerey KnVerey removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Mar 27, 2023
@koba1t
Copy link
Member

koba1t commented Mar 28, 2023

Hi @plobsing
Thanks for explaining this problem!

And, your PR failed to lint check.
Looks like this fail is not the specific line on your PR, So could you try rebase master? Maybe that fixes this failure.

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!

Otherwise, a value consisting of a single quote character triggers a
panic:

    go test krusty/configmaps_test.go
    --- FAIL: TestDataIsSingleQuote (0.00s)
    panic: runtime error: slice bounds out of range [1:0] [recovered]
    	panic: runtime error: slice bounds out of range [1:0]
Copy link
Contributor Author

@plobsing plobsing left a comment

Choose a reason for hiding this comment

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

And, your PR failed to lint check. Looks like this fail is not the specific line on your PR, So could you try rebase master? Maybe that fixes this failure.

Thanks for the advice. Rebased, although I'm still seeing what appear to be problems with make lint locally so I'm not entirely confident I've cleared the issue (it seems like go fmt is taking issue with several files not modified by this PR).

@koba1t
Copy link
Member

koba1t commented Mar 29, 2023

make lint is success on my laptop. Looks good for your PR!
Thanks for your contribution!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 29, 2023
@KnVerey
Copy link
Contributor

KnVerey commented Mar 29, 2023

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KnVerey, plobsing

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 29, 2023
@k8s-ci-robot k8s-ci-robot merged commit 3b395a9 into kubernetes-sigs:master Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants