Fix linking URLs/domains with trailing punctuation
This commit is contained in:
parent
17126aa662
commit
3ce2c34709
2 changed files with 25 additions and 4 deletions
|
@ -19,7 +19,7 @@ defmodule Linkify.Parser do
|
|||
|
||||
@match_skipped_tag ~r/^(?<tag>(a|code|pre)).*>*/
|
||||
|
||||
@delimiters ~r/[,.;:>]*$/
|
||||
@delimiters ~r/[,.;:>?!]*$/
|
||||
|
||||
@prefix_extra [
|
||||
"magnet:?",
|
||||
|
@ -249,7 +249,7 @@ defmodule Linkify.Parser do
|
|||
true
|
||||
|
||||
true ->
|
||||
tld = host |> String.trim_trailing(".") |> String.split(".") |> List.last()
|
||||
tld = host |> strip_punctuation() |> String.split(".") |> List.last()
|
||||
MapSet.member?(@tlds, tld)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -675,13 +675,33 @@ defmodule LinkifyTest do
|
|||
assert Linkify.link(text) == expected
|
||||
end
|
||||
|
||||
test "Does not link trailing punctuation" do
|
||||
test "Do not link trailing punctuation" do
|
||||
text = "You can find more info at https://pleroma.social."
|
||||
|
||||
expected =
|
||||
"You can find more info at <a href=\"https://pleroma.social\">https://pleroma.social</a>."
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
|
||||
text = "Of course it was google.com!!"
|
||||
|
||||
expected = "Of course it was <a href=\"http://google.com\">google.com</a>!!"
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
|
||||
text =
|
||||
"First I had to login to hotmail.com, then I had to delete emails because my 15MB quota was full."
|
||||
|
||||
expected =
|
||||
"First I had to login to <a href=\"http://hotmail.com\">hotmail.com</a>, then I had to delete emails because my 15MB quota was full."
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
|
||||
text = "I looked at theonion.com; it was no longer funny."
|
||||
|
||||
expected = "I looked at <a href=\"http://theonion.com\">theonion.com</a>; it was no longer funny."
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
end
|
||||
|
||||
test "IDN and punycode domain" do
|
||||
|
@ -693,7 +713,8 @@ defmodule LinkifyTest do
|
|||
|
||||
text = "xn--fraubcher-u9a.com says Neiiighhh!"
|
||||
|
||||
expected = "<a href=\"http://xn--fraubcher-u9a.com\">xn--fraubcher-u9a.com</a> says Neiiighhh!"
|
||||
expected =
|
||||
"<a href=\"http://xn--fraubcher-u9a.com\">xn--fraubcher-u9a.com</a> says Neiiighhh!"
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue