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
|
# 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
|
## 0.4.0 - 2020-11-24
|
||||||
|
|
||||||
|
|
|
@ -258,23 +258,9 @@ defmodule Linkify.Parser do
|
||||||
end
|
end
|
||||||
|
|
||||||
def ip?(buffer) do
|
def ip?(buffer) do
|
||||||
v4 = String.split(buffer, ".")
|
case :inet.parse_strict_address(to_charlist(buffer)) do
|
||||||
|
{:error, _} -> false
|
||||||
v6 =
|
{:ok, _} -> true
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -1,7 +1,7 @@
|
||||||
defmodule Linkify.Mixfile do
|
defmodule Linkify.Mixfile do
|
||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
@version "0.4.0"
|
@version "0.4.1"
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
|
|
|
@ -760,5 +760,21 @@ defmodule LinkifyTest do
|
||||||
|
|
||||||
assert Linkify.link(text) == expected
|
assert Linkify.link(text) == expected
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue