diff --git a/lib/alerts/url_parsing_helpers.ex b/lib/alerts/url_parsing_helpers.ex index 1865436365..845f141876 100644 --- a/lib/alerts/url_parsing_helpers.ex +++ b/lib/alerts/url_parsing_helpers.ex @@ -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 diff --git a/test/alerts/url_parsing_helpers_test.exs b/test/alerts/url_parsing_helpers_test.exs index c3cd2d1290..3d76f9a3af 100644 --- a/test/alerts/url_parsing_helpers_test.exs +++ b/test/alerts/url_parsing_helpers_test.exs @@ -26,9 +26,14 @@ defmodule Alerts.URLParsingHelpersTest do test "should return the url with special characters parsed from the text" do word_fn = &Faker.Internet.domain_word/0 + # Characters between ! and @ : !\"#$%&'()*+,-./0123456789:;<=>?@ + special_chars = + Enum.to_list(33..64) + |> Enum.map(fn x -> <> end) + |> List.to_string() url = - "#{Faker.Util.pick(["http", "https"])}://#{word_fn.()}.#{Faker.Internet.domain_name()}/#{word_fn.()}/#{word_fn.()}?#{word_fn.()}=#{word_fn.()}¶m_2=hello%20world##{word_fn.()}" + "#{Faker.Util.pick(["http", "https"])}://#{word_fn.()}.#{Faker.Internet.domain_name()}/#{word_fn.()}/#{word_fn.()}?#{word_fn.()}=[#{word_fn.()}]¶m_2=hello%20world##{word_fn.()}#{special_chars}" text = "This is a test for url validation, the following URL should be completely parsed: #{url} "