未验证 提交 1dd87ce2 编写于 作者: K kyle 提交者: GitHub

fix: refuse to render non-string Markdown field values (via #5295)

上级 f50bbecc
......@@ -19,6 +19,10 @@ DomPurify.addHook("beforeSanitizeElements", function (current, ) {
const isPlainText = (str) => /^[A-Z\s0-9!?\.]+$/gi.test(str)
function Markdown({ source, className = "" }) {
if (typeof source !== "string") {
return null
}
if(isPlainText(source)) {
// If the source text is not Markdown,
// let's save some time and just render it.
......
......@@ -10,6 +10,10 @@ parser.block.ruler.enable(["table"])
parser.set({ linkTarget: "_blank" })
export const Markdown = ({ source, className = "" }) => {
if(typeof source !== "string") {
return null
}
if ( source ) {
const html = parser.render(source)
const sanitized = sanitizer(html)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册