fix(editor): UI enhancements and fixes for expression inputs (#8996)

This commit is contained in:
Elias Meire
2024-03-29 16:01:32 +01:00
committed by GitHub
parent 1cbd044e41
commit 8788e2a35b
12 changed files with 41 additions and 86 deletions

View File

@@ -382,7 +382,10 @@ function parseJson(value: string): unknown {
try {
return JSON.parse(value);
} catch (error) {
return undefined;
if (value.includes("'")) {
throw new ExpressionExtensionError("Parsing failed. Check you're using double quotes");
}
throw new ExpressionExtensionError('Parsing failed');
}
}

View File

@@ -270,7 +270,13 @@ describe('Data Transformation Functions', () => {
test1: 1,
test2: '2',
});
expect(evaluate('={{ "hi".parseJson() }}')).toBeUndefined();
});
test('.parseJson should throw on invalid JSON', () => {
expect(() => evaluate("={{ \"{'test1':1,'test2':'2'}\".parseJson() }}")).toThrowError(
"Parsing failed. Check you're using double quotes",
);
expect(() => evaluate('={{ "No JSON here".parseJson() }}')).toThrowError('Parsing failed');
});
test('.toBoolean should work on a string', () => {