Skip to content

Commit 15b53e5

Browse files
committed
Don't return non-primitives from Excel
1 parent 221068c commit 15b53e5

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/columns/fast-formula-parser.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@ const run: glide.Column = (formula, ...params) => {
4747
if (formula?.value === undefined) return undefined;
4848
const position = { row: 1, col: 1, sheet: 0 };
4949
try {
50-
return parser.parse(formula.value, position);
50+
const v = parser.parse(formula.value, position);
51+
// fast-formula-parser can return non-primitives such as arrays, but
52+
// also error objects, none of which we want to, or are allowed to,
53+
// return.
54+
if (typeof v === "number" || typeof v === "string" || typeof v === "boolean") {
55+
return v;
56+
} else {
57+
return undefined;
58+
}
5159
} catch (err) {}
5260
};
5361

@@ -100,5 +108,9 @@ export default glide.column({
100108
{ params: { formula: "SUM(A1, A2)", A1: 4, A2: "4" }, expectedResult: 8 },
101109
{ params: { formula: "SUM(A1, A2, 5)", A1: "5", A2: "10" }, expectedResult: 20 },
102110
{ params: { formula: 'UPPER("hello")' }, expectedResult: "HELLO" },
111+
{
112+
params: { formula: 'IF(ISBLANK(A1),"",REPLACE(A1,FIND(" ",A1),1,""))', A1: "Unknown" },
113+
expectedResult: undefined,
114+
},
103115
],
104116
});

0 commit comments

Comments
 (0)