Skip to content

Commit 90b37cc

Browse files
authored
Release v4.3.3 (#535)
* Fix parsing bugs with some special encoded URLs * Email parse fix Not for mailto
1 parent 91b3cd5 commit 90b37cc

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

packages/linkifyjs/src/parser.mjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ export function init({ groups }) {
152152
tt(Email, tk.DOT, EmailDomainDot);
153153
tt(Email, tk.HYPHEN, EmailDomainHyphen);
154154

155-
// Final possible email states
156-
const EmailColon = tt(Email, tk.COLON); // URL followed by colon (potential port number here)
157-
/*const EmailColonPort = */ ta(EmailColon, groups.numeric, mtk.Email); // URL followed by colon and port number
158-
159155
// Account for dots and hyphens. Hyphens are usually parts of domain names
160156
// (but not TLDs)
161157
const DomainHyphen = tt(Domain, tk.HYPHEN); // domain followed by hyphen
@@ -236,17 +232,19 @@ export function init({ groups }) {
236232
// Continue not accepting for open brackets
237233
tt(UrlNonaccept, OPEN, UrlOpen);
238234

239-
// Closing bracket component. This character WILL be included in the URL
240-
tt(UrlOpen, CLOSE, Url);
241-
242-
// URL that beings with an opening bracket, followed by a symbols.
235+
// URL that begins with an opening bracket, followed by a symbols.
243236
// Note that the final state can still be `UrlOpen` (if the URL has a
244237
// single opening bracket for some reason).
245238
const UrlOpenQ = makeState(mtk.Url);
246239
ta(UrlOpen, qsAccepting, UrlOpenQ);
247240

248241
const UrlOpenSyms = makeState(); // UrlOpen followed by some symbols it cannot end it
249-
ta(UrlOpen, qsNonAccepting);
242+
ta(UrlOpen, qsNonAccepting, UrlOpenSyms);
243+
244+
// Closing bracket component. This character WILL be included in the URL.
245+
// Must come after qsNonAccepting (which includes all close-bracket tokens)
246+
// so that CLOSE -> Url wins over CLOSE -> UrlOpenSyms.
247+
tt(UrlOpen, CLOSE, Url);
250248

251249
// URL that begins with an opening bracket, followed by some symbols
252250
ta(UrlOpenQ, qsAccepting, UrlOpenQ);

test/spec/linkifyjs/parser.test.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ const tests = [
332332
'.',
333333
],
334334
],
335+
[
336+
'https://zh.wikipedia.org/wiki/%E7%B4%85_(%E5%BC%B5%E5%9C%8B%E6%A6%AE%E5%B0%88%E8%BC%AF)',
337+
[Url],
338+
['https://zh.wikipedia.org/wiki/%E7%B4%85_(%E5%BC%B5%E5%9C%8B%E6%A6%AE%E5%B0%88%E8%BC%AF)'],
339+
],
340+
['toto@example.com:123', [Email, Text], ['toto@example.com', ':123']],
335341
];
336342

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

0 commit comments

Comments
 (0)