Skip to content

Commit 841dcaf

Browse files
authored
Merge branch 'master' into feature/misuse-of-findIndex
2 parents 064bebe + 4c2a6f4 commit 841dcaf

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/core/components/providers/markdown.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ const sanitizeOptions = {
1111

1212
function Markdown({ source }) {
1313
const sanitized = sanitize(source, sanitizeOptions)
14+
15+
// sometimes the sanitizer returns "undefined" as a string
16+
if(!source || !sanitized || sanitized === "undefined") {
17+
return null
18+
}
19+
1420
return <Remarkable
1521
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
1622
source={sanitized}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-env mocha */
2+
import React from "react"
3+
import expect from "expect"
4+
import { render } from "enzyme"
5+
import Markdown from "components/providers/markdown"
6+
7+
describe("UI-3279: Empty Markdown inputs causing bare `undefined` in output", function(){
8+
it("should return no text for `null` as source input", function(){
9+
let props = {
10+
source: null
11+
}
12+
13+
let el = render(<Markdown {...props}/>)
14+
15+
expect(el.text()).toEqual("")
16+
})
17+
18+
it("should return no text for `undefined` as source input", function(){
19+
let props = {
20+
source: undefined
21+
}
22+
23+
let el = render(<Markdown {...props}/>)
24+
25+
expect(el.text()).toEqual("")
26+
})
27+
28+
it("should return no text for empty string as source input", function(){
29+
let props = {
30+
source: ""
31+
}
32+
33+
let el = render(<Markdown {...props}/>)
34+
35+
expect(el.text()).toEqual("")
36+
})
37+
})

0 commit comments

Comments
 (0)