Merge branch 'release/0.4.1' into 'master'
Release/0.4.1 See merge request pleroma/elixir-libraries/linkify!36
This commit is contained in:
commit
bd7a759911
4 changed files with 25 additions and 19 deletions
|
@ -1,6 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
## 0.4.1 - 2020-12-21
|
||||
|
||||
### Fixed
|
||||
|
||||
- Incorrect detection of IPv4 addresses causing random numbers (e.g., $123.45) to get linked
|
||||
|
||||
## 0.4.0 - 2020-11-24
|
||||
|
||||
|
|
|
@ -258,23 +258,9 @@ defmodule Linkify.Parser do
|
|||
end
|
||||
|
||||
def ip?(buffer) do
|
||||
v4 = String.split(buffer, ".")
|
||||
|
||||
v6 =
|
||||
buffer
|
||||
|> String.trim_leading("[")
|
||||
|> String.trim_trailing("]")
|
||||
|> String.split(":", trim: true)
|
||||
|
||||
cond do
|
||||
length(v4) == 4 ->
|
||||
!Enum.any?(v4, fn x -> safe_to_integer(x, 10) not in 0..255 end)
|
||||
|
||||
length(v6) in 1..8 ->
|
||||
!Enum.any?(v4, fn x -> safe_to_integer(x, 16) not in 0..0xFFFF end)
|
||||
|
||||
false ->
|
||||
false
|
||||
case :inet.parse_strict_address(to_charlist(buffer)) do
|
||||
{:error, _} -> false
|
||||
{:ok, _} -> true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -1,7 +1,7 @@
|
|||
defmodule Linkify.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
@version "0.4.0"
|
||||
@version "0.4.1"
|
||||
|
||||
def project do
|
||||
[
|
||||
|
|
|
@ -760,5 +760,21 @@ defmodule LinkifyTest do
|
|||
|
||||
assert Linkify.link(text) == expected
|
||||
end
|
||||
|
||||
test "IPv4 is linked" do
|
||||
text = "1.1.1.1"
|
||||
|
||||
expected = "<a href=\"http://1.1.1.1\">1.1.1.1</a>"
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
end
|
||||
|
||||
test "shortened IPv4 are not linked" do
|
||||
text = "109.99"
|
||||
|
||||
expected = "109.99"
|
||||
|
||||
assert Linkify.link(text) == expected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue