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

Allow escaping dollar sign in command and script #2130

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cbandy
Copy link

@cbandy cbandy commented Nov 5, 2024

Explanation

I want to pass a literal containing $$ to my command operation as an argument. Unfortunately, Chainsaw removes this value when/before invoking the command.

Related issue

Proposed Changes

This treats pairs of dollar signs as an escape representing one dollar sign. This matches Kubernetes' behavior for container command and args fields.

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Further Comments

The behavior of os.Expand is undefined and inconsistent for runs of dollar signs U+0024. Without this change, the proposed test fails:

$ go test ./pkg/utils/env
--- FAIL: TestExpand (0.00s)
    --- FAIL: TestExpand/escape (0.00s)
        expand_test.go:45: 
                Error Trace:    .../chainsaw/pkg/utils/env/expand_test.go:45
                Error:          Not equal: 
                                expected: []string{"echo", "DO $ END", "$$", "$literal"}
                                actual  : []string{"echo", "DO  END", "$$$$", "literal"}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -2,5 +2,5 @@
                                  (string) (len=4) "echo",
                                - (string) (len=8) "DO $ END",
                                - (string) (len=2) "$$",
                                - (string) (len=8) "$literal"
                                + (string) (len=7) "DO  END",
                                + (string) (len=4) "$$$$",
                                + (string) (len=7) "literal"
                                 }
                Test:           TestExpand/escape
FAIL
FAIL    github.com/kyverno/chainsaw/pkg/utils/env       0.008s
FAIL

@cbandy cbandy requested a review from a team as a code owner November 5, 2024 16:24
The behavior of os.Expand is undefined and inconsistent for runs of
dollar signs U+0024. This treats pairs of dollar signs as an escape
representing one dollar sign. This matches Kubernetes' behavior for
container command and args fields.

Signed-off-by: Chris Bandy <bandy.chris@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant