fix(engine): 🐛 Multi-line var parsing for webhook
This commit is contained in:
@ -142,11 +142,15 @@ export const executeWebhook =
|
|||||||
...basicAuth,
|
...basicAuth,
|
||||||
json:
|
json:
|
||||||
contentType !== 'x-www-form-urlencoded' && body
|
contentType !== 'x-www-form-urlencoded' && body
|
||||||
? safeJsonParse(parseVariables(variables)(body))
|
? safeJsonParse(
|
||||||
|
parseVariables(variables, { escapeLineBreaks: true })(body)
|
||||||
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
form:
|
form:
|
||||||
contentType === 'x-www-form-urlencoded' && body
|
contentType === 'x-www-form-urlencoded' && body
|
||||||
? safeJsonParse(parseVariables(variables)(body))
|
? safeJsonParse(
|
||||||
|
parseVariables(variables, { escapeLineBreaks: true })(body)
|
||||||
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -7,7 +7,10 @@ export const stringContainsVariable = (str: string): boolean =>
|
|||||||
export const parseVariables =
|
export const parseVariables =
|
||||||
(
|
(
|
||||||
variables: Variable[],
|
variables: Variable[],
|
||||||
options: { fieldToParse: 'value' | 'id' } = { fieldToParse: 'value' }
|
options: { fieldToParse?: 'value' | 'id'; escapeLineBreaks?: boolean } = {
|
||||||
|
fieldToParse: 'value',
|
||||||
|
escapeLineBreaks: false,
|
||||||
|
}
|
||||||
) =>
|
) =>
|
||||||
(text: string | undefined): string => {
|
(text: string | undefined): string => {
|
||||||
if (!text || text === '') return ''
|
if (!text || text === '') return ''
|
||||||
@ -17,11 +20,12 @@ export const parseVariables =
|
|||||||
return matchedVarName === v.name && isDefined(v.value)
|
return matchedVarName === v.name && isDefined(v.value)
|
||||||
})
|
})
|
||||||
if (!variable) return ''
|
if (!variable) return ''
|
||||||
return (
|
if (options.fieldToParse === 'id') return variable.id
|
||||||
(options.fieldToParse === 'value'
|
const { value } = variable
|
||||||
? variable.value?.toString()
|
if (!value) return ''
|
||||||
: variable.id) || ''
|
if (options.escapeLineBreaks)
|
||||||
)
|
return value.toString().replace(/\n/g, '\\n')
|
||||||
|
return value.toString()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user