Skip to content

Commit b3f3196

Browse files
fix(table): treat a blank table_v2 filter/order editor field as absent
Clearing the Filter or Order field in Editor mode is the ordinary way to say 'no filter'. `JSON.parse('')` throws, so it surfaced at run time as `Invalid JSON in Filter: Unexpected end of JSON input` plus a quoting hint that has nothing to do with the actual problem. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011M563cbFy2S74GvSDf2C3R
1 parent 0df4d58 commit b3f3196

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

apps/sim/blocks/blocks/table_v2.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,29 @@ describe('table_v2 bulk transformers', () => {
9191
expect(out.filter).toEqual({ all: [{ field: 'name', op: 'eq', value: 'x' }] })
9292
})
9393
})
94+
95+
/**
96+
* The Filter/Order fields are canonical pairs: a builder array in Builder mode,
97+
* a JSON string in Editor mode. Clearing the editor field is the ordinary way to
98+
* say "no filter" — it must not surface as a JSON parse error at run time.
99+
*/
100+
describe('table_v2 blank and malformed editor inputs', () => {
101+
const base = { operation: 'query_rows', tableId: 'tbl_1', limit: '10' }
102+
103+
it('treats a blank / whitespace filter or order as absent', () => {
104+
for (const value of ['', ' ', '\n']) {
105+
expect(params({ ...base, filterInput: value }).filter).toBeUndefined()
106+
expect(params({ ...base, sortInput: value }).order).toBeUndefined()
107+
}
108+
})
109+
110+
it('treats an empty builder array as absent', () => {
111+
expect(params({ ...base, filterInput: [] }).filter).toBeUndefined()
112+
expect(params({ ...base, sortInput: [] }).order).toBeUndefined()
113+
})
114+
115+
it('still reports genuinely malformed JSON', () => {
116+
expect(() => params({ ...base, filterInput: '{not json}' })).toThrow(/Invalid JSON in Filter/)
117+
expect(() => params({ ...base, sortInput: '{not json}' })).toThrow(/Invalid JSON in Sort/)
118+
})
119+
})

apps/sim/blocks/blocks/table_v2.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import { getTrigger } from '@/triggers'
1818

1919
function parseJSON(value: string | unknown, fieldName: string): unknown {
2020
if (typeof value !== 'string') return value
21+
// A blank editor field means "no filter/order", not malformed JSON. Without
22+
// this, clearing the field throws `Unexpected end of JSON input` at run time.
23+
if (value.trim() === '') return undefined
2124
try {
2225
return JSON.parse(value)
2326
} catch (error) {

0 commit comments

Comments
 (0)