From 07213b998f2232989e9d5286878eb50e13288aae Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 23 Apr 2022 17:28:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B8=A6=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E7=9A=84bbcode=20=E5=86=85=E5=AE=B9=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BC=9A=E5=87=BA=E7=8E=B0=E9=97=AE=E9=A2=98=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__snapshots__/render.spec.tsx.snap | 18 ++++++++++++++++++ .../src/__tests__/render.spec.tsx | 11 +++++++++++ .../src/bbcode/__tests__/parser.spec.ts | 16 ++++++++++++++++ .../com.msgbyte.bbcode/src/bbcode/parser.tsx | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 web/plugins/com.msgbyte.bbcode/src/__tests__/__snapshots__/render.spec.tsx.snap create mode 100644 web/plugins/com.msgbyte.bbcode/src/__tests__/render.spec.tsx diff --git a/web/plugins/com.msgbyte.bbcode/src/__tests__/__snapshots__/render.spec.tsx.snap b/web/plugins/com.msgbyte.bbcode/src/__tests__/__snapshots__/render.spec.tsx.snap new file mode 100644 index 00000000..01883699 --- /dev/null +++ b/web/plugins/com.msgbyte.bbcode/src/__tests__/__snapshots__/render.spec.tsx.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`render mention with space name 1`] = ` +
+ + @ + Notify Bot + +
+     123123
+  
+
+`; diff --git a/web/plugins/com.msgbyte.bbcode/src/__tests__/render.spec.tsx b/web/plugins/com.msgbyte.bbcode/src/__tests__/render.spec.tsx new file mode 100644 index 00000000..fffe0ae6 --- /dev/null +++ b/web/plugins/com.msgbyte.bbcode/src/__tests__/render.spec.tsx @@ -0,0 +1,11 @@ +import { render } from '@testing-library/react'; +import React from 'react'; +import BBCode from '../render'; + +describe('render ', () => { + test('mention with space name', () => { + const raw = '[at=6251986eab331ca2efbba9c6]Notify Bot[/at] 123123'; + const wrapper = render(); + expect(wrapper.container).toMatchSnapshot(); + }); +}); diff --git a/web/plugins/com.msgbyte.bbcode/src/bbcode/__tests__/parser.spec.ts b/web/plugins/com.msgbyte.bbcode/src/bbcode/__tests__/parser.spec.ts index 789f4a43..d1fd5a8d 100644 --- a/web/plugins/com.msgbyte.bbcode/src/bbcode/__tests__/parser.spec.ts +++ b/web/plugins/com.msgbyte.bbcode/src/bbcode/__tests__/parser.spec.ts @@ -56,4 +56,20 @@ describe('bbcode parser', () => { ]); }); }); + + test('with space', () => { + const ast = bbcodeParser.parse( + '[at=6251986eab331ca2efbba9c6]Notify Bot[/at] 123123' + ); + + expect(ast).toMatchObject([ + { + tag: 'at', + attrs: { at: '6251986eab331ca2efbba9c6' }, + content: ['Notify', ' ', 'Bot'], + }, + ' ', + '123123', + ]); + }); }); diff --git a/web/plugins/com.msgbyte.bbcode/src/bbcode/parser.tsx b/web/plugins/com.msgbyte.bbcode/src/bbcode/parser.tsx index cea59fa5..f22ed58b 100644 --- a/web/plugins/com.msgbyte.bbcode/src/bbcode/parser.tsx +++ b/web/plugins/com.msgbyte.bbcode/src/bbcode/parser.tsx @@ -87,7 +87,7 @@ class BBCodeParser { }) // NOTICE: 这里排序看起来好像有问题,但是attrs的顺序是有序的,所以没有问题 .join(''); - return `[${tag}${attrsStr}]${content}[/${tag}]`; + return `[${tag}${attrsStr}]${content.join('')}[/${tag}]`; }) .join(''); }