From e004539a5402a616118787ae7ffdc0d273d31c7e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 27 Jan 2021 17:42:09 -0600 Subject: [PATCH] Auto linking of IP addresses requires a scheme has been provided --- lib/linkify/parser.ex | 2 +- test/linkify_test.exs | 8 ++++++-- test/parser_test.exs | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 325b69c..c585728 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -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 diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 64489c1..8142aac 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -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 = "1.1.1.1" + assert Linkify.link(text) == text + + text = "http://1.1.1.1" + + expected = "http://1.1.1.1" assert Linkify.link(text) == expected end diff --git a/test/parser_test.exs b/test/parser_test.exs index cd00df1..c7298d2 100644 --- a/test/parser_test.exs +++ b/test/parser_test.exs @@ -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,