Auto linking of IP addresses requires a scheme has been provided

This commit is contained in:
Mark Felder 2021-01-27 17:42:09 -06:00
parent bd7a759911
commit e004539a54
3 changed files with 11 additions and 7 deletions

View file

@ -237,7 +237,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

@ -761,10 +761,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,