Commit 6ce7516f authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

馃悰 Delete the infinite loop when the last char is a parenthesis

parent 9ad2f042
Pipeline #64852 passed with stage
in 15 seconds
......@@ -80,8 +80,8 @@ const conditionsCheckOneByOne = (
conditions: FieldCondition[],
i: number,
parentArray: ConditionTranslated[],
) => {
if (conditions[i].type === 'item' && conditions[i].value === '(') {
): number => {
if (conditions[i].type === 'item' && conditions[i].value === '(' && i !== conditions.length - 1) {
i = subConditionInsert(conditions, i, parentArray);
} else if (conditionTest(conditions, i)) {
i = insertTranslation(conditions, i, parentArray);
......@@ -96,7 +96,7 @@ const conditionsCheckOneByOne = (
parentArray.push(subConditionArray[0]);
i = subConditionIFinal;
} else {
if (i !== conditions.length - 1) {
if ((conditions[i].type === 'item' && conditions[i].value === '(' && i === conditions.length - 1) || i !== conditions.length - 1) {
throw new Error('Invalid condition');
}
}
......@@ -195,42 +195,43 @@ class ConditionService {
*/
async translate(conditions: FieldCondition[], fieldId: string, type: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
const translation: ConditionTranslated[] = [];
try {
const translation: ConditionTranslated[] = [];
if (conditions.length === 1) {
translation.push({
fieldA: {
id: <string>conditions[0].id,
value: <string>conditions[0].value,
},
});
} else {
for (let i = 0; i < conditions.length; i++) {
try {
if (conditions.length === 1) {
translation.push({
fieldA: {
id: <string>conditions[0].id,
value: <string>conditions[0].value,
},
});
} else {
for (let i = 0; i < conditions.length; i++) {
i = conditionsCheckOneByOne(conditions, i, translation);
} catch (e) {
reject(e);
}
}
}
store.getters['form/getFieldById'](fieldId);
store.dispatch(
'form/updateField',
{
id: fieldId,
attribute: 'conditional',
value: {
basic: {
...store.getters['form/getFieldById'](fieldId)?.conditional?.basic,
[type]: translation,
store.getters['form/getFieldById'](fieldId);
store.dispatch(
'form/updateField',
{
id: fieldId,
attribute: 'conditional',
value: {
basic: {
...store.getters['form/getFieldById'](fieldId)?.conditional?.basic,
[type]: translation,
},
},
},
},
).then(() => {
resolve();
});
).then(() => {
resolve();
});
} catch (e) {
reject(e);
}
});
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment