From e16136f70950c60a879fbd965c871946fedb51bf Mon Sep 17 00:00:00 2001 From: Sergey Suprunenko Date: Tue, 10 Nov 2020 21:24:50 +0100 Subject: [PATCH] Do not parse mention if there is something before it --- lib/linkify/parser.ex | 2 +- test/linkify_test.exs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 1e5c3db..eab5891 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -15,7 +15,7 @@ defmodule Linkify.Parser do # @user # @user@example.com - @match_mention ~r"^@[a-zA-Z\d_-]+@[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*|@[a-zA-Z\d_-]+"u + @match_mention ~r"^@[a-zA-Z\d_-]+@[a-zA-Z0-9_-](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*|^@[a-zA-Z\d_-]+"u # https://www.w3.org/TR/html5/forms.html#valid-e-mail-address @match_email ~r"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"u diff --git a/test/linkify_test.exs b/test/linkify_test.exs index b5059f6..a18dc3c 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -385,6 +385,12 @@ defmodule LinkifyTest do mention_prefix: "https://example.com/user/" ) == expected end + + test "invalid mentions" do + text = "hey user@example" + + assert Linkify.link(text, mention: true, mention_prefix: "/users/") == text + end end describe "hashtag links" do