Skip to content

Commit 22e58d1

Browse files
authored
Treat object replacement character as whitespace (#497)
Fixes #495
1 parent efd6e80 commit 22e58d1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

packages/linkifyjs/src/scanner.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import assign from './assign.mjs';
1313
const NL = '\n'; // New line character
1414
const EMOJI_VARIATION = '\ufe0f'; // Variation selector, follows heart and others
1515
const EMOJI_JOINER = '\u200d'; // zero-width joiner
16+
const OBJECT_REPLACEMENT = '\ufffc'; // whitespace placeholder that sometimes appears in rich text editors
1617

1718
let tlds = null,
1819
utlds = null; // don't change so only have to be computed once
@@ -112,9 +113,11 @@ export function init(customSchemes = []) {
112113
// Tokens of only non-newline whitespace are arbitrarily long
113114
// If any whitespace except newline, more whitespace!
114115
const Ws = tr(Start, re.SPACE, tk.WS, { [fsm.whitespace]: true });
116+
tt(Start, OBJECT_REPLACEMENT, Ws);
115117
tt(Start, NL, tk.NL, { [fsm.whitespace]: true });
116118
tt(Ws, NL); // non-accepting state to avoid mixing whitespaces
117119
tr(Ws, re.SPACE, Ws);
120+
tt(Ws, OBJECT_REPLACEMENT, Ws);
118121

119122
// Emoji tokens. They are not grouped by the scanner except in cases where a
120123
// zero-width joiner is present

test/spec/linkifyjs/parser.test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ const tests = [
313313
[Text, Url, Text, Url, Text],
314314
['Link 1『', 'http://foo.com/blah_blah', '』 Link 2『', 'http://foo.com/blah_blah_(wikipedia)_(again)', '』'],
315315
],
316+
[
317+
'https://google.com\ufffcthis', // object replacement character
318+
[Url, Text],
319+
['https://google.com', '\ufffcthis'],
320+
],
316321
];
317322

318323
describe('linkifyjs/parser#run()', () => {

0 commit comments

Comments
 (0)