diff --git a/frontend/public/locales/en/translation.json b/frontend/public/locales/en/translation.json index 9811b52..7ed3d2e 100644 --- a/frontend/public/locales/en/translation.json +++ b/frontend/public/locales/en/translation.json @@ -100,6 +100,7 @@ "no_content_type": "No content type available, please create one first", "invalid_max_fallback_attempt_limit": "Max fallback attempt limit must have positive value", "regex_is_invalid": "Regex is invalid", + "regex_is_empty": "Regex cannot be empty", "attachment_not_found": "Attachment is not found", "title_length_exceeded": "You have reached the maximum length", "no_label_found": "No label found", diff --git a/frontend/public/locales/fr/translation.json b/frontend/public/locales/fr/translation.json index d06616c..f2390ea 100644 --- a/frontend/public/locales/fr/translation.json +++ b/frontend/public/locales/fr/translation.json @@ -100,6 +100,7 @@ "no_content_type": "Il n'y a aucun type de contenu pour le moment, veuillez en ajouter un.", "invalid_max_fallback_attempt_limit": "La limite des tentatives de secours doit être un nombre positif.", "regex_is_invalid": "Le regex est invalide", + "regex_is_empty": "Le regex ne peut pas être vide", "attachment_not_found": "La pièce jointe est introuvable", "title_length_exceeded": "Vous avez atteint la longueur maximale", "no_label_found": "Aucune étiquette trouvée", diff --git a/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx b/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx index 2e90c7f..c0152bb 100644 --- a/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx @@ -265,26 +265,26 @@ const PatternInput: FC = ({ ) : null} {typeof value === "string" && patternType === "regex" ? ( { try { - if ( - pattern.at(0) === "/" && - pattern.at(-1) === "/" && - typeof pattern === "string" - ) - new RegExp(pattern.slice(1, -1)); + const parsedPattern = new RegExp(pattern.slice(1, -1)); + + if (String(parsedPattern) !== pattern) { + throw t("message.regex_is_invalid"); + } return true; } catch (_e) { return t("message.regex_is_invalid"); } }, - setValueAs: (v) => `/${v}/`, + setValueAs: (v) => (isRegex(v) ? v : `/${v}/`), })} label={t("label.regex")} value={value.slice(1, -1)} onChange={(v) => onChange(v)} + required /> ) : null} {typeof value === "string" && patternType === "text" ? (