Merge branch 'fix/ip-urls-require-scheme' into 'master'

Require scheme to link IPv4 addresses

See merge request pleroma/elixir-libraries/linkify!40
This commit is contained in:
lain 2021-03-02 14:05:02 +00:00
commit 09e56b48d6
3 changed files with 11 additions and 7 deletions

View file

@ -300,7 +300,7 @@ defmodule Linkify.Parser do
opts[:validate_tld] == false ->
true
ip?(host) ->
scheme != "" && ip?(host) ->
true
# don't validate if scheme is present

View file

@ -768,10 +768,14 @@ defmodule LinkifyTest do
assert Linkify.link(text) == expected
end
test "IPv4 is linked" do
test "IPv4 is linked only with scheme" do
text = "1.1.1.1"
expected = "<a href=\"http://1.1.1.1\">1.1.1.1</a>"
assert Linkify.link(text) == text
text = "http://1.1.1.1"
expected = "<a href=\"http://1.1.1.1\">http://1.1.1.1</a>"
assert Linkify.link(text) == expected
end

View file

@ -275,9 +275,7 @@ defmodule Linkify.ParserTest do
"example.com",
"example.ca",
"example.tv",
"example.com:999?one=one",
"255.255.255.255",
"255.255.255.255:3000?one=1&two=2"
"example.com:999?one=one"
]
def invalid_non_scheme_urls,
@ -285,7 +283,9 @@ defmodule Linkify.ParserTest do
"invalid.com/perl.cgi?key= | web-site.com/cgi-bin/perl.cgi?key1=value1&key2",
"invalid.",
"hi..there",
"555.555.5555"
"555.555.5555",
"255.255.255.255",
"255.255.255.255:3000?one=1&two=2"
]
def custom_tld_scheme_urls,