Skip to content

Commit 47e1706

Browse files
authored
Merge pull request #519 from progfay/fix-decorationRegExp-ReDos
2 parents 1a2e78d + 75f1fa6 commit 47e1706

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

src/block/node/DecorationNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { convertToNodes } from '.'
44
import type { DecorationNode } from './type'
55
import type { NodeCreator } from './creator'
66

7-
const decorationRegExp = /\[[!"#%&'()*+,-./{|}<>_~]+ (?:\[[^\]]+\]|[^\]])+\]/
7+
const decorationRegExp = /\[[!"#%&'()*+,-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/
88

99
type DecorationChar =
1010
| '*'

tests/line/__snapshots__/decoration.test.ts.snap

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,59 @@ Array [
5959
]
6060
`;
6161

62+
exports[`decoration Decoration with many [ and link: toMatchSnapshotWhenParsing 1`] = `
63+
Array [
64+
Object {
65+
"indent": 0,
66+
"nodes": Array [
67+
Object {
68+
"raw": "[! ",
69+
"text": "[! ",
70+
"type": "plain",
71+
},
72+
Object {
73+
"nodes": Array [
74+
Object {
75+
"raw": "[[[[a",
76+
"text": "[[[[a",
77+
"type": "plain",
78+
},
79+
],
80+
"raw": "[[[[[[a]]",
81+
"type": "strong",
82+
},
83+
],
84+
"type": "line",
85+
},
86+
]
87+
`;
88+
89+
exports[`decoration Decoration with many [: toMatchSnapshotWhenParsing 1`] = `
90+
Array [
91+
Object {
92+
"indent": 0,
93+
"nodes": Array [
94+
Object {
95+
"decos": Array [
96+
"!",
97+
],
98+
"nodes": Array [
99+
Object {
100+
"raw": "[[[[[[a",
101+
"text": "[[[[[[a",
102+
"type": "plain",
103+
},
104+
],
105+
"raw": "[! [[[[[[a]",
106+
"rawDecos": "!",
107+
"type": "decoration",
108+
},
109+
],
110+
"type": "line",
111+
},
112+
]
113+
`;
114+
62115
exports[`decoration Simple decoration: toMatchSnapshotWhenParsing 1`] = `
63116
Array [
64117
Object {

tests/line/decoration.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,12 @@ describe('decoration', () => {
7373
hasTitle: false
7474
})
7575
})
76+
77+
it('Decoration with many [', () => {
78+
expect('[! [[[[[[a]').toMatchSnapshotWhenParsing({ hasTitle: false })
79+
})
80+
81+
it('Decoration with many [ and link', () => {
82+
expect('[! [[[[[[a]]').toMatchSnapshotWhenParsing({ hasTitle: false })
83+
})
7684
})

0 commit comments

Comments
 (0)