这里是我是如何做到的,因为你快速乡亲。它似乎与express-sanitizer一起工作得很好。
app.js
import expressSanitizer from 'express-sanitizer'
app.use(expressSanitizer())
app.post('/route', async (req, res) => {
const title = req.body.article.title
const content = req.sanitize(req.body.article.content)
// Do stuff with content
})
新。EJS
...
...
const quill = new Quill('#editor', {
theme: 'snow'
})
const quillContents =() => {
const form = document.forms[0]
const editor = document.createElement('input')
editor.type = 'hidden'
editor.name = 'article[content]'
editor.value = document.querySelector('.ql-editor').innerHTML
form.appendChild(editor)
return form.submit()
}
我认为只有一种形式,所以我用document.forms[0],但如果你有多个或可能在将来扩展您的看法有多种形式,请查看MDN参考。
我们在这里做的是创建一个隐藏的表单输入,我们指定Quill Div的内容,然后我们将表单提交并通过函数传递给它,以完成它。
现在,测试它,在其中发布一个的帖子,您不必担心注入漏洞。
就是这样。