Do not parse mention if there is something before it

This commit is contained in:
Sergey Suprunenko 2020-11-10 21:24:50 +01:00
parent 5581840992
commit e16136f709
No known key found for this signature in database
GPG key ID: 5DCA7D1BE3914F9C
2 changed files with 7 additions and 1 deletions

View file

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

View file

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