Skip to content

Commit

Permalink
fix(template): always prefer explicit unescape mode
Browse files Browse the repository at this point in the history
Here we need to distinguish `undefined` and `false`.
  • Loading branch information
vvagaytsev committed Aug 23, 2024
1 parent 674bfd9 commit 8df3a4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ export class ModuleResolver {
context: configContext,
contextOpts: {
allowPartial: false,
// Modules will be converted to actions later, and the actions will be properly unescaped.
// We avoid premature un-escaping here,
// because otherwise it will strip the escaped value in the module config
// to the normal template string in the converted action config.
unescape: false,
},
// Note: We're not implementing the YAML source mapping for modules
source: undefined,
Expand Down
11 changes: 10 additions & 1 deletion core/src/template-string/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ export const resolveTemplateString = profile(function resolveTemplateString({
return string
}

const shouldUnescape = (ctxOpts: ContextResolveOpts) => {
// Explicit non-escaping takes the highest priority.
if (ctxOpts.unescape === false) {
return false
}

return !!ctxOpts.unescape || !contextOpts.allowPartial
}

try {
const parsed = parser.parse(string, {
getKey: (key: string[], resolveOpts?: ContextResolveOpts) => {
Expand All @@ -135,7 +144,7 @@ export const resolveTemplateString = profile(function resolveTemplateString({
missingKeyExceptionType,
passthroughExceptionType,
allowPartial: !!contextOpts.allowPartial,
unescape: !!contextOpts.unescape || !contextOpts.allowPartial,
unescape: shouldUnescape(contextOpts),
escapePrefix,
optionalSuffix: "}?",
isPlainObject,
Expand Down

0 comments on commit 8df3a4f

Please sign in to comment.