fix: 修复带空格的bbcode 内容显示会出现问题的bug

release/desktop
moonrailgun 3 years ago
parent 7a457209b3
commit 07213b998f

@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`render <BBCode /> mention with space name 1`] = `
<div>
<span
class="plugin-bbcode-mention-tag"
data-userid="6251986eab331ca2efbba9c6"
>
@
Notify Bot
</span>
<pre
style="display: inline; white-space: break-spaces;"
>
123123
</pre>
</div>
`;

@ -0,0 +1,11 @@
import { render } from '@testing-library/react';
import React from 'react';
import BBCode from '../render';
describe('render <BBCode />', () => {
test('mention with space name', () => {
const raw = '[at=6251986eab331ca2efbba9c6]Notify Bot[/at] 123123';
const wrapper = render(<BBCode plainText={raw} />);
expect(wrapper.container).toMatchSnapshot();
});
});

@ -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',
]);
});
});

@ -87,7 +87,7 @@ class BBCodeParser {
})
// NOTICE: 这里排序看起来好像有问题但是attrs的顺序是有序的所以没有问题
.join('');
return `[${tag}${attrsStr}]${content}[/${tag}]`;
return `[${tag}${attrsStr}]${content.join('')}[/${tag}]`;
})
.join('');
}

Loading…
Cancel
Save