2
0

🐛 Fix parseVariables when preceding with a dollar sign

This commit is contained in:
Baptiste Arnaud
2023-03-24 07:42:17 +01:00
parent fa31984456
commit 5fb5176641
2 changed files with 17 additions and 12 deletions

View File

@@ -179,6 +179,7 @@ export const VariableSearchInput = ({
onFocus={onOpen}
onKeyDown={handleKeyUp}
placeholder={inputProps.placeholder ?? 'Select a variable'}
autoComplete="off"
{...inputProps}
/>
</PopoverAnchor>

View File

@@ -22,10 +22,11 @@ export const parseVariables =
(text: string | undefined): string => {
if (!text || text === '') return ''
// Capture {{variable}} and ${{{variable}}} (variables in template litterals)
const pattern = /\{\{([^{}]+)\}\}|\$\{\{([^{}]+)\}\}/g
const pattern = /\{\{([^{}]+)\}\}|(\$)\{\{([^{}]+)\}\}/g
return text.replace(
pattern,
(_, nameInCurlyBraces, nameInTemplateLitteral) => {
(_full, nameInCurlyBraces, _dollarSign, nameInTemplateLitteral) => {
const dollarSign = _dollarSign ?? ''
const matchedVarName = nameInCurlyBraces ?? nameInTemplateLitteral
const variable = variables.find((variable) => {
return (
@@ -33,19 +34,22 @@ export const parseVariables =
(options.fieldToParse === 'id' || isDefined(variable.value))
)
}) as VariableWithValue | undefined
if (!variable) return ''
if (options.fieldToParse === 'id') return variable.id
if (!variable) return dollarSign + ''
if (options.fieldToParse === 'id') return dollarSign + variable.id
const { value } = variable
if (options.escapeForJson)
return jsonParse(
typeof value !== 'string' ? JSON.stringify(value) : value
return (
dollarSign +
jsonParse(typeof value !== 'string' ? JSON.stringify(value) : value)
)
const parsedValue = safeStringify(
const parsedValue =
dollarSign +
safeStringify(
options.takeLatestIfList && Array.isArray(value)
? value[value.length - 1]
: value
)
if (!parsedValue) return ''
if (!parsedValue) return dollarSign + ''
return parsedValue
}
)