-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
pathological.js
137 lines (113 loc) · 3.05 KB
/
pathological.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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('unclosed links A', function () {
assert.match(
md.render('[a](<b'.repeat(30000)),
/(\[a\]\(<b){30000}/
);
});
it('unclosed links B', function () {
assert.match(
md.render('[a](b'.repeat(30000)),
/(\[a\]\(b){30000}/
);
});
});