From 367c5b9639ea5d644be7aa7ea8412995a6dbc5e6 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 15 May 2018 10:09:52 +0100 Subject: [PATCH] Koenig - Fixed empty HTML card rendering `undefined` refs https://github.com/TryGhost/Ghost/issues/9623 - add tests for undefined payloads in container cards - add guard for undefined payload in html card --- core/server/lib/mobiledoc/cards/html.js | 4 ++++ core/test/unit/lib/mobiledoc/cards/html_spec.js | 13 +++++++++++++ .../unit/lib/mobiledoc/cards/markdown_spec.js | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/core/server/lib/mobiledoc/cards/html.js b/core/server/lib/mobiledoc/cards/html.js index 31a9386357..7e72ce10dc 100644 --- a/core/server/lib/mobiledoc/cards/html.js +++ b/core/server/lib/mobiledoc/cards/html.js @@ -2,6 +2,10 @@ module.exports = { name: 'html', type: 'dom', render(opts) { + if (!opts.payload.html) { + return ''; + } + // use the SimpleDOM document to create a raw HTML section. // avoids parsing/rendering of potentially broken or unsupported HTML return opts.env.dom.createRawHTMLSection(opts.payload.html); diff --git a/core/test/unit/lib/mobiledoc/cards/html_spec.js b/core/test/unit/lib/mobiledoc/cards/html_spec.js index 39c130f820..331a885e76 100644 --- a/core/test/unit/lib/mobiledoc/cards/html_spec.js +++ b/core/test/unit/lib/mobiledoc/cards/html_spec.js @@ -44,4 +44,17 @@ describe('HTML card', function () { serializer.serialize(card.render(opts)).should.match('

HEADING<'); }); + + it('Renders nothing when payload is undefined', function () { + let opts = { + env: { + dom: new SimpleDom.Document() + }, + payload: { + html: undefined + } + }; + + serializer.serialize(card.render(opts)).should.match(''); + }); }); diff --git a/core/test/unit/lib/mobiledoc/cards/markdown_spec.js b/core/test/unit/lib/mobiledoc/cards/markdown_spec.js index 00cdeafe62..3ccf8b2a1a 100644 --- a/core/test/unit/lib/mobiledoc/cards/markdown_spec.js +++ b/core/test/unit/lib/mobiledoc/cards/markdown_spec.js @@ -72,5 +72,21 @@ describe('Markdown card', function () { serializer.serialize(card.render(opts)).should.match('

HEADING

\n

Heading 2>'); }); + + it('Renders nothing when payload is undefined', function () { + let opts = { + env: { + dom: new SimpleDom.Document() + }, + payload: { + markdown: undefined + }, + options: { + version: 2 + } + }; + + serializer.serialize(card.render(opts)).should.match(''); + }); }); });