Skip to content

Commit

Permalink
Koenig - Fixed empty HTML card rendering undefined
Browse files Browse the repository at this point in the history
refs #9623
- add tests for undefined payloads in container cards
- add guard for undefined payload in html card
  • Loading branch information
kevinansfield committed May 15, 2018
1 parent d10cb5c commit 367c5b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/server/lib/mobiledoc/cards/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions core/test/unit/lib/mobiledoc/cards/html_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ describe('HTML card', function () {

serializer.serialize(card.render(opts)).should.match('<h1>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('');
});
});
16 changes: 16 additions & 0 deletions core/test/unit/lib/mobiledoc/cards/markdown_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,21 @@ describe('Markdown card', function () {

serializer.serialize(card.render(opts)).should.match('<h1 id="heading">HEADING</h1>\n<h2>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('');
});
});
});

0 comments on commit 367c5b9

Please sign in to comment.