Skip to content

Commit

Permalink
Port pathological tests from cmark
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Nov 19, 2020
1 parent cadc58e commit 725a916
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions test/pathological.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Ported from cmark, https://github.com/commonmark/cmark/blob/master/test/pathological_tests.py
//

'use strict';


var assert = require('chai').assert;
var markdownit = require('../');


describe('Pathological', function () {

var md;

before(function () {
md = markdownit({ maxNesting: 100 });
});

it('nested strong emph', function () {
assert.match(
md.render('*a **a '.repeat(65000) + 'b' + ' a** a*'.repeat(65000)),
/(<em>a <strong>a ){65000}b( a<\/strong> a<\/em>){65000}/
);
});

it('many emph closers with no openers', function () {
assert.match(
md.render('a_ '.repeat(65000)),
/(a[_] ){64999}a_/
);
});

it('many emph openers with no closers', function () {
assert.match(
md.render('_a '.repeat(65000)),
/(_a ){64999}_a/
);
});

it('many link closers with no openers', function () {
assert.match(
md.render('a]'.repeat(65000)),
/(a\]){65000}/
);
});

it('many link openers with no closers', function () {
assert.match(
md.render('[a'.repeat(65000)),
/(\[a){65000}/
);
});

it('mismatched openers and closers', function () {
assert.match(
md.render('*a_ '.repeat(50000)),
/([*]a[_] ){49999}[*]a_/
);
});

it('openers and closers multiple of 3', function () {
assert.match(
md.render('a**b' + ('c* '.repeat(50000))),
/a[*][*]b(c[*] ){49999}c[*]/
);
});

it('link openers and emph closers', function () {
assert.match(
md.render('[ a_'.repeat(50000)),
/(\[ a_){50000}/
);
});

it.skip('pattern [ (]( repeated', function () {
assert.match(
md.render('[ (]('.repeat(80000)),
/(\[ \(\]\(){80000}/
);
});

it('hard link/emph case', function () {
assert.match(
md.render('**x [a*b**c*](d)'),
/\*\*x <a href="d">a<em>b\*\*c<\/em><\/a>/
);
});

it('nested brackets', function () {
assert.match(
md.render('['.repeat(50000) + 'a' + ']'.repeat(50000)),
/\[{50000}a\]{50000}/
);
});

it('nested block quotes', function () {
assert.match(
md.render('> '.repeat(50000) + 'a'),
/(<blockquote>\n){99}/ // limited by maxNesting
);
});

it('deeply nested lists', function () {
assert.match(
md.render(Array(1000).fill(0).map(function (_, x) { return ' '.repeat(x) + '* a\n'; }).join('')),
/<ul>\n(<li>a\n<ul>\n){49}<li><\/li>\n<\/ul>\n(<\/li>\n<\/ul>\n){49}/ // limited by maxNesting
);
});

it('U+0000 in input', function () {
assert.match(
md.render('abc\u0000de\u0000'),
/abc\ufffd?de\ufffd?/
);
});

it.skip('backticks', function () {
assert.match(
md.render(Array(50000).fill(0).map(function (_, x) { return 'e' + '`'.repeat(x); }).join('')),
/^<p>[e`]*<\/p>\n$/
);
});

it.skip('unclosed links A', function () {
assert.match(
md.render('[a](<b'.repeat(30000)),
/(\[a\]\(&lt;b){30000}/
);
});

it.skip('unclosed links B', function () {
assert.match(
md.render('[a](b'.repeat(30000)),
/(\[a\]\(b){30000}/
);
});
});

0 comments on commit 725a916

Please sign in to comment.