2
0

fix(engine): 🐛 Multi-line var parsing for webhook

This commit is contained in:
Baptiste Arnaud
2022-05-27 11:03:51 -07:00
parent e72934d29a
commit d02f267588
2 changed files with 16 additions and 8 deletions

View File

@ -142,11 +142,15 @@ export const executeWebhook =
...basicAuth,
json:
contentType !== 'x-www-form-urlencoded' && body
? safeJsonParse(parseVariables(variables)(body))
? safeJsonParse(
parseVariables(variables, { escapeLineBreaks: true })(body)
)
: undefined,
form:
contentType === 'x-www-form-urlencoded' && body
? safeJsonParse(parseVariables(variables)(body))
? safeJsonParse(
parseVariables(variables, { escapeLineBreaks: true })(body)
)
: undefined,
}
try {

View File

@ -7,7 +7,10 @@ export const stringContainsVariable = (str: string): boolean =>
export const parseVariables =
(
variables: Variable[],
options: { fieldToParse: 'value' | 'id' } = { fieldToParse: 'value' }
options: { fieldToParse?: 'value' | 'id'; escapeLineBreaks?: boolean } = {
fieldToParse: 'value',
escapeLineBreaks: false,
}
) =>
(text: string | undefined): string => {
if (!text || text === '') return ''
@ -17,11 +20,12 @@ export const parseVariables =
return matchedVarName === v.name && isDefined(v.value)
})
if (!variable) return ''
return (
(options.fieldToParse === 'value'
? variable.value?.toString()
: variable.id) || ''
)
if (options.fieldToParse === 'id') return variable.id
const { value } = variable
if (!value) return ''
if (options.escapeLineBreaks)
return value.toString().replace(/\n/g, '\\n')
return value.toString()
})
}