From f605f9cf2750f7b760011762692f7b45af2c5116 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 5 May 2023 09:32:12 +0100 Subject: [PATCH] Update finite automate to match user identifiers as per spec --- src/linkify-matrix.ts | 4 +++- test/linkify-matrix-test.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/linkify-matrix.ts b/src/linkify-matrix.ts index 456298ce11e..45fa06779e1 100644 --- a/src/linkify-matrix.ts +++ b/src/linkify-matrix.ts @@ -58,6 +58,8 @@ function matrixOpaqueIdLinkifyParser({ TLD, COLON, SYM, + SLASH, + EQUALS, HYPHEN, UNDERSCORE, // because 'localhost' is tokenised to the localhost token, @@ -69,7 +71,7 @@ function matrixOpaqueIdLinkifyParser({ const S_START = parser.start; const matrixSymbol = utils.createTokenClass(name, { isLink: true }); - const localpartTokens = [domain, TLD, LOCALHOST, SYM, UNDERSCORE, HYPHEN]; + const localpartTokens = [domain, TLD, DOT, LOCALHOST, SYM, SLASH, EQUALS, UNDERSCORE, HYPHEN]; const domainpartTokens = [domain, TLD, LOCALHOST, HYPHEN]; const INITIAL_STATE = S_START.tt(token); diff --git a/test/linkify-matrix-test.ts b/test/linkify-matrix-test.ts index eaab5b039d3..22694da9db5 100644 --- a/test/linkify-matrix-test.ts +++ b/test/linkify-matrix-test.ts @@ -303,6 +303,22 @@ describe("linkify-matrix", () => { describe("userid plugin", () => { genTests("@"); + + it("allows dots in localparts", () => { + const test = "@test.:matrix.org"; + const found = linkify.find(test); + expect(found).toEqual([ + { + href: test, + type: "userid", + value: test, + start: 0, + end: test.length, + + isLink: true, + }, + ]); + }); }); describe("matrix uri", () => {