fix!: resolve escaping of string values in withItems map parameters. Fixes #16061#16074
Open
gsr25 wants to merge 1 commit into
Open
fix!: resolve escaping of string values in withItems map parameters. Fixes #16061#16074gsr25 wants to merge 1 commit into
gsr25 wants to merge 1 commit into
Conversation
…ixes argoproj#16061 When using withItems with object parameters containing special characters (newlines, tabs, quotes), string values were incorrectly double-escaped. This happened because Item.String() JSON-encodes the value (escaping newlines to \n), then strconv.Quote() in the template engine escaped them again (to \\n). Use GetStrVal() for string-typed map values to properly unmarshal them, matching the behavior already used for top-level string items. Signed-off-by: gsr25 <girish.sairam@devrev.ai>
Author
|
@MasonM could I please get a review when you get a chance? Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16061
Motivation
When using
withItemswith object parameters containing multi-line strings (or other special characters like tabs and quotes), the string values get incorrectly double-escaped. For example, a YAML multiline value like:...results in the parameter containing literal
\ncharacters instead of actual newlines.This is a continuation of #13718 which fixed escaping for top-level string items but not for string values within map items.
Modifications
In
workflow/controller/operator.go, theprocessItem()function now checks if a map value is of typeStringand usesGetStrVal()(which properly JSON-unmarshals the value) instead offmt.Sprintf("%v", itemVal)(which callsItem.String(), thenjson.Marshal(), then strips quotes, leaving JSON escape sequences intact).The root cause:
Item.String()produces JSON-encoded content (e.g.,multi\nline), which then gets further escaped bystrconv.Quote()in the template engine tomulti\\nline. After finaljson.Unmarshal, this becomes literal backslash-n instead of a newline.Verification
Added unit tests in
Test_processItem_mapWithMultilineStringcovering:\n)\t)\")All existing
Test_processItemtests continue to pass.Documentation
No documentation changes needed. This is a bug fix restoring expected behavior.
AI
Claude (Opus 4.6) helped with code review, tests, and PR description.