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

the "annotate" flag does not parse the annotation value correctly if it contains comma #2402

Open
psturc opened this issue Sep 13, 2024 · 1 comment
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@psturc
Copy link

psturc commented Sep 13, 2024

Versions and Operating System

  • Kubernetes version:
    not needed to reproduce this bug

  • Tekton Pipeline version:

    Client version: 0.38.1
    
  • Operating System:

    Mac OS Sonoma 14.6.1 (23G93)
    

Expected Behavior

when using --annotate parameter with tkn bundle push command, the annotation's value is parsed correctly if it contains comma: ,

Actual Behavior

it fails with an error: Error: invalid input format for param parameter: <the rest of the annotation value string after comma>

Steps to Reproduce the Problem

Run

➜  ~ tkn bundle push --annotate 'test=a,b' quay.io/my-quay-username/my-repo:test-tag -f some-task.yaml
*Warning*: This is an experimental command, it's usage and behavior can change in the next release(s)
Error: invalid input format for param parameter: b

Additional Info

the --annotate parameter was introduced in this commit

@psturc psturc added the kind/bug Categorizes issue or PR as related to a bug. label Sep 13, 2024
@chmeliik
Copy link

chmeliik commented Sep 13, 2024

Some more investigation from a slack channel:

Ha, I found out why it does that. It uses pflag.StringSlice to parse the --annotate argument, which is very clever and, in this case, very inconvenient

It means you can pass two annotations at the same time like --annotate 'a=b,x=y'
But you can't really pass an annotation that contains a comma 😕

can the comma be escaped?

Kind of - turns out StringSlice parses the argument as a CSV file using https://pkg.go.dev/encoding/csv, so you can in fact quote them
tkn bundle push --annotate '"foo=one, two",bar=three'

Then double-quotes would cause issues instead, but those can be escaped by using double double-quotes
tkn bundle push --annotate '"foo=""Hello there!"", said Kenobi."'

TLDR - it is possible to use the flag as is, but really hard. Parsing the --annotate (and also --labels) values with StringArray, which doesn't do this CSV splitting, would be much easier to deal with.

But would also be a breaking change for anyone who's relying on the StringSlice behavior

chmeliik added a commit to chmeliik/build-definitions that referenced this issue Sep 13, 2024
Due to tektoncd/cli#2402, annotation values
that contain commas or double-quotes currently break 'tkn bundle push'.

Escape such annotation values in a way that's compatible with the
pflag.StringSlice [1] parser that 'tkn bundle push' uses to parse
CLI arguments.

https://pkg.go.dev/github.com/spf13/pflag#FlagSet.StringSlice

Signed-off-by: Adam Cmiel <[email protected]>
chmeliik added a commit to chmeliik/build-definitions that referenced this issue Sep 13, 2024
Due to tektoncd/cli#2402, annotation values
that contain commas or double-quotes currently break 'tkn bundle push'.

Escape such annotation values in a way that's compatible with the
pflag.StringSlice [1] parser that 'tkn bundle push' uses to parse
CLI arguments.

[1]: https://pkg.go.dev/github.com/spf13/pflag#FlagSet.StringSlice

Signed-off-by: Adam Cmiel <[email protected]>
github-merge-queue bot pushed a commit to konflux-ci/build-definitions that referenced this issue Sep 13, 2024
Due to tektoncd/cli#2402, annotation values
that contain commas or double-quotes currently break 'tkn bundle push'.

Escape such annotation values in a way that's compatible with the
pflag.StringSlice [1] parser that 'tkn bundle push' uses to parse
CLI arguments.

[1]: https://pkg.go.dev/github.com/spf13/pflag#FlagSet.StringSlice

Signed-off-by: Adam Cmiel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants