Merge branch 'fix/fqdn-domain' into 'master'

Support linking URLs with FQDNs

See merge request pleroma/elixir-libraries/linkify!30
This commit is contained in:
feld 2020-11-18 17:47:54 +00:00
commit b50bd58d70
3 changed files with 24 additions and 1 deletions

View file

@ -2,6 +2,10 @@
## [Unreleased]
### Added
- Support for linking URLs with FQDNs (e.g., "google.com.")
## 0.3.0 - 2020-11-17
### Added

View file

@ -247,7 +247,7 @@ defmodule Linkify.Parser do
true
true ->
tld = host |> String.split(".") |> List.last()
tld = host |> String.trim_trailing(".") |> String.split(".") |> List.last()
MapSet.member?(@tlds, tld)
end
end

View file

@ -657,5 +657,24 @@ defmodule LinkifyTest do
assert Linkify.link(text) == expected
end
test "FQDN (with trailing period)" do
text =
"Check out this article: https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/"
expected =
"Check out this article: <a href=\"https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/\">https://www.wired.com./story/marissa-mayer-startup-sunshine-contacts/</a>"
assert Linkify.link(text) == expected
end
test "Does 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
end
end
end