Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/components/providers/markdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const sanitizeOptions = {

function Markdown({ source }) {
const sanitized = sanitize(source, sanitizeOptions)

// sometimes the sanitizer returns "undefined" as a string
if(!source || !sanitized || sanitized === "undefined") {
return null
}

return <Remarkable
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
source={sanitized}
Expand Down
37 changes: 37 additions & 0 deletions test/bugs/3279-empty-markdown-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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("")
})
})