Skip to content

Commit 7dced57

Browse files
fix(renderText): special case @ symbol at the end of the message (#1873)
* fix: handle special case of @ symbol at the end of the message * test: add test for special case with @ symbol
1 parent 6ec31af commit 7dced57

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/__tests__/__snapshots__/utils.test.js.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`renderText handles the special case where there's at least one mention and @ symbol at the end 1`] = `
4+
<p>
5+
<span
6+
className="str-chat__message-mention"
7+
data-user-id="[email protected]"
8+
>
9+
10+
</span>
11+
@
12+
</p>
13+
`;
14+
315
exports[`renderText handles the special case where user name matches to an e-mail pattern - 1 1`] = `
416
<p>
517
Hello

src/__tests__/utils.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,12 @@ describe(`renderText`, () => {
8080
const tree = renderer.create(Markdown).toJSON();
8181
expect(tree).toMatchSnapshot();
8282
});
83+
84+
it("handles the special case where there's at least one mention and @ symbol at the end", () => {
85+
const Markdown = renderText('@[email protected] @', [
86+
87+
]);
88+
const tree = renderer.create(Markdown).toJSON();
89+
expect(tree).toMatchSnapshot();
90+
});
8391
});

src/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export const mentionsMarkdownPlugin = <
188188
if (!parent) return;
189189

190190
const nextChild = parent.children.at(index + 1) as Element;
191-
const nextChildHref = nextChild?.properties?.href as string;
191+
const nextChildHref = nextChild?.properties?.href as string | undefined;
192192

193193
if (
194194
node.type === 'text' &&
@@ -197,7 +197,7 @@ export const mentionsMarkdownPlugin = <
197197
// valid cases: "text @", "@", " @"
198198
// invalid cases: "text@", "@text",
199199
/.?\s?@$|^@$/.test(node.value) &&
200-
nextChildHref.startsWith('mailto:')
200+
nextChildHref?.startsWith('mailto:')
201201
) {
202202
const newTextValue = node.value.replace(/@$/, '');
203203
const username = nextChildHref.replace('mailto:', '');

0 commit comments

Comments
 (0)