From c9199b582dbe80fbbed0a0bcb72b4080d864250c Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 16 Feb 2017 20:59:07 +0300 Subject: [PATCH] Better error message for bad input type, close #324 --- lib/index.js | 4 ++++ test/misc.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/index.js b/lib/index.js index 0803058..b531720 100644 --- a/lib/index.js +++ b/lib/index.js @@ -514,6 +514,10 @@ MarkdownIt.prototype.use = function (plugin /*, params, ... */) { * and then pass updated object to renderer. **/ MarkdownIt.prototype.parse = function (src, env) { + if (typeof src !== 'string') { + throw new Error('Input data should be a String'); + } + var state = new this.core.State(src, this, env); this.core.process(state); diff --git a/test/misc.js b/test/misc.js index 0497642..5b20392 100644 --- a/test/misc.js +++ b/test/misc.js @@ -145,6 +145,15 @@ describe('API', function () { assert(md.renderInline('_foo_'), 'foo'); }); + it('input type check', function () { + var md = markdownit(); + + assert.throws( + function () { md.render(null); }, + /Input data should be a String/ + ); + }); + });