fix double dot issue
This commit is contained in:
parent
783b64aaac
commit
b30df6cb37
3 changed files with 18 additions and 6 deletions
|
@ -16,6 +16,11 @@ defmodule AutoLinker.Parser do
|
||||||
"Check out <a href='http://google.com' class='auto-linker' target='_blank' rel='noopener noreferrer'>google.com</a>"
|
"Check out <a href='http://google.com' class='auto-linker' target='_blank' rel='noopener noreferrer'>google.com</a>"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@match_dots ~r/\.\.+/
|
||||||
|
|
||||||
|
@match_url ~r{^[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
|
||||||
|
@match_scheme ~r{^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
|
||||||
|
|
||||||
def parse(text, opts \\ %{})
|
def parse(text, opts \\ %{})
|
||||||
def parse(text, list) when is_list(list), do: parse(text, Enum.into(list, %{}))
|
def parse(text, list) when is_list(list), do: parse(text, Enum.into(list, %{}))
|
||||||
|
|
||||||
|
@ -79,12 +84,18 @@ defmodule AutoLinker.Parser do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def is_url?(buffer, true) do
|
def is_url?(buffer, true) do
|
||||||
re = ~r{^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
|
if Regex.match? @match_dots, buffer do
|
||||||
Regex.match? re, buffer
|
false
|
||||||
|
else
|
||||||
|
Regex.match? @match_scheme, buffer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
def is_url?(buffer, _) do
|
def is_url?(buffer, _) do
|
||||||
re = ~r{^[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$}
|
if Regex.match? @match_dots, buffer do
|
||||||
Regex.match? re, buffer
|
false
|
||||||
|
else
|
||||||
|
Regex.match? @match_url, buffer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
|
|
2
mix.exs
2
mix.exs
|
@ -1,7 +1,7 @@
|
||||||
defmodule AutoLinker.Mixfile do
|
defmodule AutoLinker.Mixfile do
|
||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
@version "0.1.0"
|
@version "0.1.1"
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[
|
[
|
||||||
|
|
|
@ -86,7 +86,8 @@ defmodule AutoLinker.ParserTest do
|
||||||
|
|
||||||
def invalid_non_scheme_urls, do: [
|
def invalid_non_scheme_urls, do: [
|
||||||
"invalid.com/perl.cgi?key= | web-site.com/cgi-bin/perl.cgi?key1=value1&key2",
|
"invalid.com/perl.cgi?key= | web-site.com/cgi-bin/perl.cgi?key1=value1&key2",
|
||||||
"invalid."
|
"invalid.",
|
||||||
|
"hi..there"
|
||||||
]
|
]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue