Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(DecorationNode): improve Inefficient regular expression #519

Merged
merged 2 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 })
})
})