Skip to content

Commit

Permalink
Merge pull request #519 from progfay/fix-decorationRegExp-ReDos
Browse files Browse the repository at this point in the history
  • Loading branch information
progfay authored Feb 7, 2021
2 parents 1a2e78d + 75f1fa6 commit 47e1706
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/block/node/DecorationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { convertToNodes } from '.'
import type { DecorationNode } from './type'
import type { NodeCreator } from './creator'

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

type DecorationChar =
| '*'
Expand Down
53 changes: 53 additions & 0 deletions tests/line/__snapshots__/decoration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,59 @@ Array [
]
`;

exports[`decoration Decoration with many [ and link: toMatchSnapshotWhenParsing 1`] = `
Array [
Object {
"indent": 0,
"nodes": Array [
Object {
"raw": "[! ",
"text": "[! ",
"type": "plain",
},
Object {
"nodes": Array [
Object {
"raw": "[[[[a",
"text": "[[[[a",
"type": "plain",
},
],
"raw": "[[[[[[a]]",
"type": "strong",
},
],
"type": "line",
},
]
`;

exports[`decoration Decoration with many [: toMatchSnapshotWhenParsing 1`] = `
Array [
Object {
"indent": 0,
"nodes": Array [
Object {
"decos": Array [
"!",
],
"nodes": Array [
Object {
"raw": "[[[[[[a",
"text": "[[[[[[a",
"type": "plain",
},
],
"raw": "[! [[[[[[a]",
"rawDecos": "!",
"type": "decoration",
},
],
"type": "line",
},
]
`;

exports[`decoration Simple decoration: toMatchSnapshotWhenParsing 1`] = `
Array [
Object {
Expand Down
8 changes: 8 additions & 0 deletions tests/line/decoration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ describe('decoration', () => {
hasTitle: false
})
})

it('Decoration with many [', () => {
expect('[! [[[[[[a]').toMatchSnapshotWhenParsing({ hasTitle: false })
})

it('Decoration with many [ and link', () => {
expect('[! [[[[[[a]]').toMatchSnapshotWhenParsing({ hasTitle: false })
})
})

0 comments on commit 47e1706

Please sign in to comment.