diff --git a/lib/marked.js b/lib/marked.js index 9cf56ce2..fce4f4c4 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -285,6 +285,11 @@ block.token = function(src, tokens, top) { }); continue; } + + if (src) { + throw new + Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } } return tokens; @@ -465,6 +470,11 @@ inline.lexer = function(src) { out += escape(cap[0]); continue; } + + if (src) { + throw new + Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } } return out; @@ -704,7 +714,15 @@ noop.exec = noop; function marked(src, opt) { setOptions(opt); - return parse(block.lexer(src)); + try { + return parse(block.lexer(src)); + } catch (e) { + e.message += '\nPlease report this to https://github.com/chjj/marked.'; + if (marked.options.silent) { + return 'An error occured: ' + e.message; + } + throw e; + } } /**