From 21100a0a8b5e2db75c40c001d049ba3787f75192 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Thu, 22 Jun 2017 22:05:38 -0700 Subject: [PATCH 1/2] Don't render Markdown if input or sanitized input is empty --- src/core/components/providers/markdown.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/components/providers/markdown.jsx b/src/core/components/providers/markdown.jsx index d058d17617f..8ebce12c0c0 100644 --- a/src/core/components/providers/markdown.jsx +++ b/src/core/components/providers/markdown.jsx @@ -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 Date: Thu, 22 Jun 2017 22:11:37 -0700 Subject: [PATCH 2/2] Add tests --- test/bugs/3279-empty-markdown-source.js | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/bugs/3279-empty-markdown-source.js diff --git a/test/bugs/3279-empty-markdown-source.js b/test/bugs/3279-empty-markdown-source.js new file mode 100644 index 00000000000..276c87d1e27 --- /dev/null +++ b/test/bugs/3279-empty-markdown-source.js @@ -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() + + expect(el.text()).toEqual("") + }) + + it("should return no text for `undefined` as source input", function(){ + let props = { + source: undefined + } + + let el = render() + + expect(el.text()).toEqual("") + }) + + it("should return no text for empty string as source input", function(){ + let props = { + source: "" + } + + let el = render() + + expect(el.text()).toEqual("") + }) +})