From cb3b305be08b5092c844d9c5a247db7fe54fc68a Mon Sep 17 00:00:00 2001 From: progfay Date: Sun, 7 Feb 2021 18:37:40 +0900 Subject: [PATCH 1/2] test(DecorationNode): add testcase with many [ --- .../__snapshots__/decoration.test.ts.snap | 53 +++++++++++++++++++ tests/line/decoration.test.ts | 8 +++ 2 files changed, 61 insertions(+) diff --git a/tests/line/__snapshots__/decoration.test.ts.snap b/tests/line/__snapshots__/decoration.test.ts.snap index 6dfacc37..76bd8892 100644 --- a/tests/line/__snapshots__/decoration.test.ts.snap +++ b/tests/line/__snapshots__/decoration.test.ts.snap @@ -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 { diff --git a/tests/line/decoration.test.ts b/tests/line/decoration.test.ts index c6aeb0ad..605544e2 100644 --- a/tests/line/decoration.test.ts +++ b/tests/line/decoration.test.ts @@ -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 }) + }) }) From 75f1fa6d23cecaa4d2d5d1a60c4a1d2a4178f5c6 Mon Sep 17 00:00:00 2001 From: progfay Date: Sun, 7 Feb 2021 18:38:23 +0900 Subject: [PATCH 2/2] fix(DecorationNode): fix Inefficient regular expression (reported by CodeQL) - report: https://github.com/progfay/scrapbox-parser/security/code-scanning/1?query=ref%3Arefs%2Fpull%2F518%2Fhead --- src/block/node/DecorationNode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/block/node/DecorationNode.ts b/src/block/node/DecorationNode.ts index 8d0d210d..8cbc6455 100644 --- a/src/block/node/DecorationNode.ts +++ b/src/block/node/DecorationNode.ts @@ -4,7 +4,7 @@ import { convertToNodes } from '.' import type { DecorationNode } from './type' import type { NodeCreator } from './creator' -const decorationRegExp = /\[[!"#%&'()*+,-./{|}<>_~]+ (?:\[[^\]]+\]|[^\]])+\]/ +const decorationRegExp = /\[[!"#%&'()*+,-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/ type DecorationChar = | '*'