Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading