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.
This commit is contained in:
+23
@@ -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 =
|
||||
|
||||
+5
-1
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user