Browse Source

Improve performance in `skipToken` when maxNesting is exceeded

pull/204/merge
Alex Kocharin 9 years ago
parent
commit
53aec24168
  1. 13
      lib/parser_inline.js
  2. 2
      lib/presets/default.js
  3. 2
      test/misc.js

13
lib/parser_inline.js

@ -93,6 +93,19 @@ ParserInline.prototype.skipToken = function (state) {
if (ok) { break; }
}
} else {
// Too much nesting, just skip until the end of the paragraph.
//
// NOTE: this will cause links to behave incorrectly in the following case,
// when an amount of `[` is exactly equal to `maxNesting + 1`:
//
// [[[[[[[[[[[[[[[[[[[[[foo]()
//
// TODO: remove this workaround when CM standard will allow nested links
// (we can replace it by preventing links from being parsed in
// validation mode)
//
state.pos = state.posMax;
}
if (!ok) { state.pos++; }

2
lib/presets/default.js

@ -29,7 +29,7 @@ module.exports = {
//
highlight: null,
maxNesting: 20 // Internal protection, recursion limit
maxNesting: 100 // Internal protection, recursion limit
},
components: {

2
test/misc.js

@ -281,7 +281,7 @@ describe('maxNesting', function () {
var md = markdownit({ maxNesting: 2 });
assert.strictEqual(
md.render('[[[[[[[[[[[[[[[[[[foo]()'),
'<p>[[[[[[[[[[[[[[[[[<a href="">foo</a></p>\n'
'<p>[[[[[[[[[[[[[[[[[[foo]()</p>\n'
);
});

Loading…
Cancel
Save