From f9e817d9fb5097fcb603a78612c2114b3ff0705f Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sun, 15 Nov 2015 19:45:26 +0100 Subject: [PATCH 1/2] return null on non-string input --- lib/marked.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/marked.js b/lib/marked.js index 03251f3c58..8ab79819e4 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1144,6 +1144,9 @@ function merge(obj) { */ function marked(src, opt, callback) { + // return null in case of non valid input + if (typeof src != 'string') return null; + if (callback || typeof opt === 'function') { if (!callback) { callback = opt; From 1ec0bf387f2f4795217c787f49facff5e5cc9ecc Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Tue, 2 Jan 2018 15:10:01 +0100 Subject: [PATCH 2/2] print more descriptive error messages when source is undefined (as in #979) --- lib/marked.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 8ab79819e4..e6f8804e28 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1144,8 +1144,13 @@ function merge(obj) { */ function marked(src, opt, callback) { - // return null in case of non valid input - if (typeof src != 'string') return null; + // throw error in case of non string input + if (typeof src == 'undefined' || src === null) + throw new Error('marked(): input parameter is undefined or null'); + if (typeof src != 'string') + throw new Error('marked(): input parameter is of type ' + + Object.prototype.toString.call(src) + ', string expected'); + if (callback || typeof opt === 'function') { if (!callback) {