From 11f6da95a7f6ea45f5201d964f6faa28d15e9955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Wed, 19 Jun 2024 09:07:09 +0400 Subject: [PATCH] Fix restricted char --- components/konstitisyon/handle-comments.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/konstitisyon/handle-comments.js b/components/konstitisyon/handle-comments.js index b4d0c52..6252276 100644 --- a/components/konstitisyon/handle-comments.js +++ b/components/konstitisyon/handle-comments.js @@ -14,7 +14,7 @@ import LogoutCountdown from '../session/logout-countdown.js' import {directusClient} from '@/lib/directus.js' function hasRestrictedChar(text) { - const regex = /[<>&'"]/g + const regex = /[<>&"]/g return Boolean(regex.test(text)) } @@ -32,10 +32,11 @@ export default function HandleComments({session, selectedTitre, isOpen, setIsOpe const formData = new FormData(e.currentTarget) const formJson = Object.fromEntries(formData.entries()) const {comment} = formJson + const formattedComment = comment.replaceAll('\'', '’') try { - if (hasRestrictedChar(comment)) { - setError('Le texte ne doit pas contenir certains caractères spéciaux : <, >, \', ".') + if (hasRestrictedChar(formattedComment)) { + setError('Le texte ne doit pas contenir certains caractères spéciaux : <, >, ", .') setIsErrorAlertOpen(true) return @@ -44,7 +45,7 @@ export default function HandleComments({session, selectedTitre, isOpen, setIsOpe await directusClient.request(withToken( session.user.accessToken, createItem('commentaires', { - text: comment, + text: formattedComment, titre: selectedTitre, status: 'draft' })