Skip to content

Draft: Ensure text interpolation preserves input type

Avielle Wolfe requested to merge 439272-fix-text-interpolation into master

What does this MR do and why?

In order to avoid indentation errors, text interpolation casts most input types to JSON before inserting them into the YAML content. However, casting strings to JSON adds quotes around them, which breaks interpolation when inserting a string into another string. For example, $[[ inputs.job_name ]]_job becomes "test"_job instead of test_job.

To get around this, we don't cast strings to JSON. However, this creates another problem where strings that look like other data types (for example, "true" or "6.6") get interpolated as non-strings (true and 6.6) when we don't include the quotes.

This MR fixes the situation by checking whether we are inserting the string between whitespace. When we insert between whitespace, we cast the string to JSON to ensure it gets parsed as a string. When we insert it into another string, we don't cast it to JSON to avoid getting the undesired quotes.

Issue: #439272 (closed)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Merge request reports