avoid infinite loops

This commit is contained in:
Christopher Jeffrey 2012-11-23 10:33:47 -06:00
parent cc9bfe2c00
commit a80ed87b0c

View File

@ -285,6 +285,11 @@ block.token = function(src, tokens, top) {
}); });
continue; continue;
} }
if (src) {
throw new
Error('Infinite loop on byte: ' + src.charCodeAt(0));
}
} }
return tokens; return tokens;
@ -465,6 +470,11 @@ inline.lexer = function(src) {
out += escape(cap[0]); out += escape(cap[0]);
continue; continue;
} }
if (src) {
throw new
Error('Infinite loop on byte: ' + src.charCodeAt(0));
}
} }
return out; return out;
@ -704,7 +714,15 @@ noop.exec = noop;
function marked(src, opt) { function marked(src, opt) {
setOptions(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;
}
} }
/** /**