fix: prevent TypeError when accessing undefined TI18nString values in findLanguageCodesForDuplicateLabels

Fixes FORMBRICKS-JM

- Updated findLanguageCodesForDuplicateLabels in both validation.ts and elements-validation.ts
- Changed to safely filter undefined values before calling .trim()
- Now filters for string type first, then trims, then filters empty strings
- Prevents 'undefined is not an object (evaluating e[r].trim)' error when survey labels are incomplete
This commit is contained in:
Cursor Agent
2026-02-13 01:19:23 +00:00
parent 18a7b233f0
commit f55b9de3a2
2 changed files with 8 additions and 3 deletions

View File

@@ -104,8 +104,9 @@ export const findLanguageCodesForDuplicateLabels = (
for (const language of languagesToCheck) {
const labelTexts = labels
.map((label) => label[language])
.filter((text): text is string => typeof text === "string" && text.trim().length > 0)
.map((text) => text.trim());
.filter((text): text is string => typeof text === "string")
.map((text) => text.trim())
.filter((text) => text.length > 0);
const uniqueLabels = new Set(labelTexts);
if (uniqueLabels.size !== labelTexts.length) {

View File

@@ -224,7 +224,11 @@ export const findLanguageCodesForDuplicateLabels = (
const duplicateLabels = new Set<string>();
for (const language of languagesToCheck) {
const labelTexts = labels.map((label) => label[language].trim()).filter(Boolean);
const labelTexts = labels
.map((label) => label[language])
.filter((text): text is string => typeof text === "string")
.map((text) => text.trim())
.filter((text) => text.length > 0);
const uniqueLabels = new Set(labelTexts);
if (uniqueLabels.size !== labelTexts.length) {