Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/alerts/url_parsing_helpers.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Alerts.URLParsingHelpers do
@moduledoc "Helpers to parse out the url from a string and create an html link"

@url_regex ~r/(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})([\/\w\.-\?&%#]*)*\/?/i
@url_regex ~r/(https?:\/\/)?([\da-z\.-]+)\.([a-z]{2,6})([\/\w\!-\@_\[\]]*)*\/?/i

@spec get_full_url(String.t()) :: String.t() | nil
def get_full_url(text) do
Expand Down
8 changes: 7 additions & 1 deletion test/alerts/url_parsing_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ defmodule Alerts.URLParsingHelpersTest do

test "should return the url with special characters parsed from the text" do
word_fn = &Faker.Internet.domain_word/0
# \"#$%&'()*+,-./0123456789:;<=>?@
special_chars =
Enum.to_list(33..64) # numbers corresponding to ASCII characters between ! and @
|> Enum.map(fn x -> <<x::utf8>> end)
|> List.to_string

url =
"#{Faker.Util.pick(["http", "https"])}://#{word_fn.()}.#{Faker.Internet.domain_name()}/#{word_fn.()}/#{word_fn.()}?#{word_fn.()}=#{word_fn.()}&param_2=hello%20world##{word_fn.()}"
"#{Faker.Util.pick(["http", "https"])}://#{word_fn.()}.#{Faker.Internet.domain_name()}/#{word_fn.()}/#{word_fn.()}?#{word_fn.()}=#{word_fn.()}&param_2=hello%20world##{word_fn.()}#{special_chars}"
|> dbg()

text =
"This is a test for url validation, the following URL should be completely parsed: #{url} "
Expand Down
Loading