Added warning msg when variables detect infinite expansion (WIP)

This commit is contained in:
Jason Casareno
2022-08-10 18:01:34 -07:00
parent d0f4080771
commit 631a16feb0
2 changed files with 51 additions and 2 deletions

View File

@@ -110,3 +110,26 @@ export const parseTemplateString = (
parseTemplateStringE(str, variables, myVariables),
E.getOrElse(() => str)
)
export function parseMyVariablesString(
str: string,
variables: Variables,
) {
if (!variables || !str) {
return E.right(str)
}
let result = str
let depthVar = 0
while (result.match(REGEX_MY_VAR) != null && depthVar <= ENV_MAX_EXPAND_LIMIT) {
result = decodeURI(encodeURI(result)).replace(
REGEX_MY_VAR,
(_, p1) => variables.find((x) => x.key === p1)?.value || ""
)
depthVar++
}
return depthVar <= ENV_MAX_EXPAND_LIMIT ? E.right(result) : E.left(ENV_EXPAND_LOOP);
}