Fix link previews for messages with emojis

Co-authored-by: Elias Zamaria <mikez302@gmail.com>
This commit is contained in:
automated-signal 2025-09-26 15:23:21 -05:00 committed by GitHub
commit c232bb21f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -116,6 +116,24 @@ describe('Link previews', () => {
assert.deepEqual(expected, actual);
});
it('returns all links after emojis with spaces in between, if a caretLocation is provided', () => {
const text = '😎 https://github.com/signalapp/Signal-Desktop';
const expected = ['https://github.com/signalapp/Signal-Desktop'];
const actual = findLinks(text, 45);
assert.deepEqual(expected, actual);
});
it('returns all links after a complex emoji, if a caretLocation is provided', () => {
const text = '👨‍👩‍👦 https://github.com/signalapp/Signal-Desktop';
const expected = ['https://github.com/signalapp/Signal-Desktop'];
const actual = findLinks(text, 45);
assert.deepEqual(expected, actual);
});
it('includes all links if cursor is not in a link', () => {
const text =
'Check out this link: https://github.com/signalapp/Signal-Desktop\nAnd this one too: https://github.com/signalapp/Signal-Android';

View file

@ -10,6 +10,7 @@ import LinkifyIt from 'linkify-it';
import { maybeParseUrl } from '../util/url.js';
import { replaceEmojiWithSpaces } from '../util/emoji.js';
import { count } from '../util/grapheme.js';
import type { AttachmentWithHydratedData } from './Attachment.js';
import {
@ -167,7 +168,7 @@ export function findLinks(text: string, caretLocation?: number): Array<string> {
}
const haveCaretLocation = isNumber(caretLocation);
const textLength = text ? text.length : 0;
const textLength = count(text || '');
const matches = linkify.match(text ? replaceEmojiWithSpaces(text) : '') || [];
return compact(