Fix restricted char
This commit is contained in:
@@ -14,7 +14,7 @@ import LogoutCountdown from '../session/logout-countdown.js'
|
|||||||
import {directusClient} from '@/lib/directus.js'
|
import {directusClient} from '@/lib/directus.js'
|
||||||
|
|
||||||
function hasRestrictedChar(text) {
|
function hasRestrictedChar(text) {
|
||||||
const regex = /[<>&'"]/g
|
const regex = /[<>&"]/g
|
||||||
|
|
||||||
return Boolean(regex.test(text))
|
return Boolean(regex.test(text))
|
||||||
}
|
}
|
||||||
@@ -32,10 +32,11 @@ export default function HandleComments({session, selectedTitre, isOpen, setIsOpe
|
|||||||
const formData = new FormData(e.currentTarget)
|
const formData = new FormData(e.currentTarget)
|
||||||
const formJson = Object.fromEntries(formData.entries())
|
const formJson = Object.fromEntries(formData.entries())
|
||||||
const {comment} = formJson
|
const {comment} = formJson
|
||||||
|
const formattedComment = comment.replaceAll('\'', '’')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (hasRestrictedChar(comment)) {
|
if (hasRestrictedChar(formattedComment)) {
|
||||||
setError('Le texte ne doit pas contenir certains caractères spéciaux : <, >, \', ".')
|
setError('Le texte ne doit pas contenir certains caractères spéciaux : <, >, ", .')
|
||||||
setIsErrorAlertOpen(true)
|
setIsErrorAlertOpen(true)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -44,7 +45,7 @@ export default function HandleComments({session, selectedTitre, isOpen, setIsOpe
|
|||||||
await directusClient.request(withToken(
|
await directusClient.request(withToken(
|
||||||
session.user.accessToken,
|
session.user.accessToken,
|
||||||
createItem('commentaires', {
|
createItem('commentaires', {
|
||||||
text: comment,
|
text: formattedComment,
|
||||||
titre: selectedTitre,
|
titre: selectedTitre,
|
||||||
status: 'draft'
|
status: 'draft'
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user