Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 609732b711 fix: handle plain string SELECT filter values in arrayOfStringsOrVariablesSchema
https://sonarly.com/issue/18660?type=bug

A SELECT-type view filter with a plain string value (not a JSON array) causes a `JSON.parse` crash when loading the People record table, because `arrayOfStringsOrVariablesSchema` has no fallback for non-JSON, non-variable string values.
2026-03-26 12:09:44 +00:00
2 changed files with 28 additions and 1 deletions
@@ -61,6 +61,29 @@ describe('arrayOfStringsOrVariablesSchema', () => {
});
});
describe('Legacy plain string handling', () => {
it('should wrap plain string values in an array', () => {
const plainStrings = ['Privat', 'Work', 'some-option-value'];
plainStrings.forEach((str) => {
const result = arrayOfStringsOrVariablesSchema.safeParse(str);
expect(result.success).toBe(true);
if (result.success) {
expect(result.data).toEqual([str]);
}
});
});
it('should handle plain string with special characters', () => {
const result =
arrayOfStringsOrVariablesSchema.safeParse('Privat & Geschäftlich');
expect(result.success).toBe(true);
if (result.success) {
expect(result.data).toEqual(['Privat & Geschäftlich']);
}
});
});
describe('Edge cases', () => {
it('should handle whitespace in variable syntax', () => {
const result =
@@ -8,7 +8,11 @@ export const arrayOfStringsOrVariablesSchema = z
if (isValidVariable(val) as boolean) {
return [val];
}
return JSON.parse(val);
try {
return JSON.parse(val);
} catch {
return [val];
}
})
.refine(
(parsed) =>