Skip to content

fix!: resolve escaping of string values in withItems map parameters. Fixes #16061#16074

Open
gsr25 wants to merge 1 commit into
argoproj:mainfrom
gsr25:fix/withitems-map-string-escaping
Open

fix!: resolve escaping of string values in withItems map parameters. Fixes #16061#16074
gsr25 wants to merge 1 commit into
argoproj:mainfrom
gsr25:fix/withitems-map-string-escaping

Conversation

@gsr25

@gsr25 gsr25 commented May 10, 2026

Copy link
Copy Markdown

Fixes #16061

Motivation

When using withItems with 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:

withItems:
  - key: |
      multi
      line

...results in the parameter containing literal \n characters 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, the processItem() function now checks if a map value is of type String and uses GetStrVal() (which properly JSON-unmarshals the value) instead of fmt.Sprintf("%v", itemVal) (which calls Item.String(), then json.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 by strconv.Quote() in the template engine to multi\\nline. After final json.Unmarshal, this becomes literal backslash-n instead of a newline.

Verification

Added unit tests in Test_processItem_mapWithMultilineString covering:

  • Map with multiline string value (\n)
  • Map with tab characters (\t)
  • Map with embedded quotes (\")

All existing Test_processItem tests 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.

…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>
@gsr25 gsr25 marked this pull request as draft May 10, 2026 12:21
@gsr25 gsr25 marked this pull request as ready for review May 10, 2026 12:23
@gsr25

gsr25 commented May 26, 2026

Copy link
Copy Markdown
Author

@MasonM could I please get a review when you get a chance? Thank you!

@MasonM MasonM self-requested a review May 31, 2026 20:19
@Joibel Joibel changed the title fix: resolve escaping of string values in withItems map parameters. Fixes #16061 fix!: resolve escaping of string values in withItems map parameters. Fixes #16061 Jun 9, 2026
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.

Escaping problems on string values inside object parameters (withParams/withItems)

1 participant