提交 4c2a6f45 编写于 作者: S shockey 提交者: GitHub

Merge pull request #3287 from shockey/bug/3279-markdown-falsey-values

Don't render Markdown if input or sanitized input is empty
...@@ -11,6 +11,12 @@ const sanitizeOptions = { ...@@ -11,6 +11,12 @@ const sanitizeOptions = {
function Markdown({ source }) { function Markdown({ source }) {
const sanitized = sanitize(source, sanitizeOptions) const sanitized = sanitize(source, sanitizeOptions)
// sometimes the sanitizer returns "undefined" as a string
if(!source || !sanitized || sanitized === "undefined") {
return null
}
return <Remarkable return <Remarkable
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}} options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
source={sanitized} source={sanitized}
......
/* eslint-env mocha */
import React from "react"
import expect from "expect"
import { render } from "enzyme"
import Markdown from "components/providers/markdown"
describe("UI-3279: Empty Markdown inputs causing bare `undefined` in output", function(){
it("should return no text for `null` as source input", function(){
let props = {
source: null
}
let el = render(<Markdown {...props}/>)
expect(el.text()).toEqual("")
})
it("should return no text for `undefined` as source input", function(){
let props = {
source: undefined
}
let el = render(<Markdown {...props}/>)
expect(el.text()).toEqual("")
})
it("should return no text for empty string as source input", function(){
let props = {
source: ""
}
let el = render(<Markdown {...props}/>)
expect(el.text()).toEqual("")
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册