Skip to content

Commit

Permalink
fix: ensure conditional blocks without matching else() do not render …
Browse files Browse the repository at this point in the history
…content
  • Loading branch information
zijiren233 committed Aug 20, 2024
1 parent 6e00334 commit 1ecbb4c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions frontend/providers/template/src/utils/json-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,14 @@ const __parseYamlIfEndif = (yamlStr: string, evaluateExpression: (exp: string) =
const end = yamlStr.substring(match.index! + match[0].length);
let between = '';

let conditionMet = false;
if (elifElseMatches.length === 0) {
const ifResult = evaluateExpression(ifMatch[2]);
if (ifResult) {
between = yamlStr.substring(ifMatch.index! + ifMatch[0].length, match.index);
conditionMet = true;
}
} else {
let conditionMet = false;
for (const clause of [ifMatch, ...elifElseMatches]) {
const expression = clause[2];
if (clause[1] === 'else' || evaluateExpression(expression)) {
Expand All @@ -246,10 +247,10 @@ const __parseYamlIfEndif = (yamlStr: string, evaluateExpression: (exp: string) =
break;
}
}
}

if (!conditionMet) {
between = yamlStr.substring(elifElseMatches[elifElseMatches.length - 1].index! + elifElseMatches[elifElseMatches.length - 1][0].length, match.index);
}
if (!conditionMet && elifElseMatches.length === 0) {
between = '';
}

return __parseYamlIfEndif(start + between + end, evaluateExpression);
Expand Down

0 comments on commit 1ecbb4c

Please sign in to comment.