From 056d7f2f3708863bb7ddcb29e8be9f14c53b29f5 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Mon, 18 Feb 2019 19:06:06 +0700 Subject: [PATCH] improve mentions matching --- lib/auto_linker/parser.ex | 2 +- test/auto_linker_test.exs | 20 ++------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index 2e8a97b..0448cdd 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -40,7 +40,7 @@ defmodule AutoLinker.Parser do # @user # @user@example.com - @match_mention ~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 + @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/auto_linker_test.exs b/test/auto_linker_test.exs index 7ac672e..ad26d81 100644 --- a/test/auto_linker_test.exs +++ b/test/auto_linker_test.exs @@ -30,19 +30,15 @@ defmodule AutoLinkerTest do test "all kinds of links" do text = - "hello @user google.com https://ddg.com 888 888-8888 #tag user@email.com [google.com](http://google.com) irc:///mIRC" + "hello google.com https://ddg.com 888 888-8888 user@email.com [google.com](http://google.com) irc:///mIRC" expected = - "hello @user google.com ddg.com 888 888-8888 #tag user@email.com google.com irc:///mIRC" + "hello google.com ddg.com 888 888-8888 user@email.com google.com irc:///mIRC" assert AutoLinker.link(text, phone: true, markdown: true, email: true, - mention: true, - mention_prefix: "https://example.com/user/", - hashtag: true, - hashtag_prefix: "https://example.com/tag/", scheme: true, extra: true, class: false, @@ -143,18 +139,6 @@ defmodule AutoLinkerTest do mention_prefix: "https://example.com/user/" ) == expected end - - test "skip if starts with @@" do - text = "hello @@user and @anotherUser" - - expected = - "hello @@user and @anotherUser" - - assert AutoLinker.link(text, - mention: true, - mention_prefix: "https://example.com/user/" - ) == expected - end end describe "hashtag links" do