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' })