Skip to content

Commit

Permalink
Treat object replacement character as whitespace (#497)
Browse files Browse the repository at this point in the history
Fixes #495
  • Loading branch information
nfrasser authored Dec 4, 2024
1 parent efd6e80 commit 22e58d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/linkifyjs/src/scanner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import assign from './assign.mjs';
const NL = '\n'; // New line character
const EMOJI_VARIATION = '\ufe0f'; // Variation selector, follows heart and others
const EMOJI_JOINER = '\u200d'; // zero-width joiner
const OBJECT_REPLACEMENT = '\ufffc'; // whitespace placeholder that sometimes appears in rich text editors

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

// Emoji tokens. They are not grouped by the scanner except in cases where a
// zero-width joiner is present
Expand Down
5 changes: 5 additions & 0 deletions test/spec/linkifyjs/parser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ const tests = [
[Text, Url, Text, Url, Text],
['Link 1『', 'http://foo.com/blah_blah', '』 Link 2『', 'http://foo.com/blah_blah_(wikipedia)_(again)', '』'],
],
[
'https://google.com\ufffcthis', // object replacement character
[Url, Text],
['https://google.com', '\ufffcthis'],
],
];

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

0 comments on commit 22e58d1

Please sign in to comment.