Allow double dots in links

This commit is contained in:
tusooa 2022-12-28 12:15:35 -05:00
parent d5ae88725a
commit 0e62e64339
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
2 changed files with 14 additions and 1 deletions

View file

@ -301,7 +301,15 @@ defmodule Linkify.Parser do
end
end
defp valid_url?(url), do: !Regex.match?(@invalid_url, url)
defp valid_url?(url) do
with {_, [scheme]} <- {:regex, Regex.run(@get_scheme_host, url, capture: [:scheme])},
true <- scheme == "" do
!Regex.match?(@invalid_url, url)
else
_ ->
true
end
end
@doc """
Validates a URL's TLD. Returns a boolean.

View file

@ -226,6 +226,11 @@ defmodule Linkify.ParserTest do
assert parse(text) == "(check out <a href=\"http://google.com\">google.com</a>)"
end
test "double dot in link is allowed" do
text = "https://example.to/something..mp3"
assert parse(text) == "<a href=\"#{text}\">#{text}</a>"
end
test "do not link urls" do
text = "google.com"
assert parse(text, url: false) == text