logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: e16136f70950c60a879fbd965c871946fedb51bf
parent 55818409927c3c351a1b2f343a12dc2f36521844
Author: Sergey Suprunenko <suprunenko.s@gmail.com>
Date:   Tue, 10 Nov 2020 21:24:50 +0100

Do not parse mention if there is something before it

Diffstat:

Mlib/linkify/parser.ex2+-
Mtest/linkify_test.exs6++++++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git 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 @@ -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