Chart builder: escape ./[/] in built field names

This commit is contained in:
2026-06-11 19:21:28 +03:00
parent d666599a58
commit 983c052f3b
2 changed files with 31 additions and 7 deletions
+21
View File
@@ -674,6 +674,20 @@ describe('buildChartSpec', () => {
expect((spec.mark as { type: string }).type).toBe(mark);
}
});
it('escapes `.`/`[`/`]` in encoded field names so they read as literal columns', () => {
const spec = buildChartSpec({
datasetName: 'D',
mark: 'point',
encodings: {
x: { field: 'user.age', type: 'quantitative' },
y: { field: 'cols[0]', type: 'quantitative' },
},
});
const enc = spec.encoding as Record<string, { field: string }>;
expect(enc.x.field).toBe('user\\.age');
expect(enc.y.field).toBe('cols\\[0\\]');
});
});
describe('transforms — aggregate / bin / timeUnit', () => {
@@ -940,6 +954,13 @@ describe('buildTransforms (predicate coercion + shape)', () => {
expect(t).toEqual([{ filter: 'datum.value > 0' }]);
});
it('escapes `.`/`[`/`]` in a predicate field so it reads as a literal column', () => {
const t = buildTransforms(
withFilters(filter({ field: 'user.age', fieldType: 'quantitative', op: 'gt', value: '10' })),
);
expect(t).toEqual([{ filter: { field: 'user\\.age', gt: 10 } }]);
});
it('skips incomplete entries (blank value, blank range bound, blank expression)', () => {
const t = buildTransforms(
withFilters(