Skip to content

Commit ac67672

Browse files
committed
fix(markdown): possibilité d'utiliser une comparaison entre variables dynamiques
1 parent 418e4a4 commit ac67672

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

app/js/markdown/custom/variablesDynamic/checkConditionalBlock.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export function checkConditionalBlock(condition, dynamicVariables) {
1717
.replaceAll(
1818
/(==|!=|<=|>=|<|>) ?(.*?) ?(\)|&|\||$)/g,
1919
function (match, comparisonSignLeft, value, comparisonSignRight) {
20-
return `${comparisonSignLeft}"${value}" ${comparisonSignRight}`;
20+
const isComparisonWithDynamicVariables =
21+
value.includes("dynamicVariables");
22+
return isComparisonWithDynamicVariables
23+
? `${comparisonSignLeft}${value} ${comparisonSignRight}`
24+
: `${comparisonSignLeft}"${value}" ${comparisonSignRight}`;
2125
},
2226
)
2327
.replaceAll('""', '"')

app/js/markdown/custom/variablesDynamic/evaluateExpression.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const sanitizeCodeAllowedOperations = [
3232
".trim",
3333
",",
3434
".",
35+
"[",
36+
"]",
3537
];
3638

3739
// Nettoie une formule de test avant exécution dynamique (new Function).
@@ -67,13 +69,15 @@ function sanitizeCode(code) {
6769
const forbiddenExpressions = codeWithoutAllowedOperations
6870
.split("///")
6971
.map((exp) => exp.trim()) // On ne doit pas retirer les espaces
72+
.map(
73+
(exp) => exp !== "tryConvertStringToNumber" && exp !== "dynamicVariables",
74+
) // On ne doit pas retirer les comparaisons avec d'autre variables dynamiques
7075
.filter((exp) => exp && exp !== "undefined"); // On ne doit pas retirer la formule "undefined"
7176

7277
// On retire ces fragments interdits du code initial
7378
for (const forbidden of forbiddenExpressions) {
7479
code = code.replaceAll(forbidden, "");
7580
}
76-
7781
return code;
7882
}
7983

app/script.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/script.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)