mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-19 19:21:15 -05:00
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:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user