fix(template-strings): do not apply helper functions on unresolved string #4692
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.
What this PR does / why we need it:
Before this fix, helper functions were being applied even on resolved string and the unsubstituted string was considered the string itself for helper function.
Basically, in the first resolveTemplateStrings of module, when only
inputs
are available and keys likeenvironment
are missing, unresolved strings are fine asallowPartial
is set totrue
. However, the helper functions were still being applied.For example, for a template string like
base64Encode was being called for
environment.namespace
instead of the actual value and resulted in wrong values. So before the 2nd resolveTemplateStrings of module, when the module context is available, there was nobase64Encode(\"${environment.namespace}\")
left to be resolved.The workaround mentioned in original issue #4614
TEST: "${environment && base64Encode(\"${environment.namespace}\")}"
works because of the
environment &&
. Even though thebase64Encode
is applied onenvironment.namespace
, the overall expression fails due toenvironment
missing in first pass.I added a check before helper functions are applied to not apply helper on unresolved string. Had to wrap
text
in${}
so it's returned as an expression to be resolved later. In case,allowPartial
is set tofalse
, it returns error.Which issue(s) this PR fixes:
Fixes #4614
Special notes for your reviewer:
I am not sure if we can avoid this check altogether and instead extend the actual parser to address this issue. 🤔