diff --git a/lib/livebook/content_loader.ex b/lib/livebook/content_loader.ex index 993bc87ec..b358668c3 100644 --- a/lib/livebook/content_loader.ex +++ b/lib/livebook/content_loader.ex @@ -18,10 +18,10 @@ defmodule Livebook.ContentLoader do """ @spec rewrite_url(String.t()) :: String.t() def rewrite_url(url) do - case URI.new(url) do - {:ok, uri} -> uri |> do_rewrite_url() |> URI.to_string() - {:error, _} -> url - end + url + |> URI.parse() + |> do_rewrite_url() + |> URI.to_string() end defp do_rewrite_url(%URI{host: "github.com"} = uri) do diff --git a/lib/livebook/file_system/s3.ex b/lib/livebook/file_system/s3.ex index 714b02c31..2c14f6b23 100644 --- a/lib/livebook/file_system/s3.ex +++ b/lib/livebook/file_system/s3.ex @@ -366,7 +366,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do headers = opts[:headers] || [] body = opts[:body] - %{host: host} = URI.new!(file_system.bucket_url) + %{host: host} = URI.parse(file_system.bucket_url) url = file_system.bucket_url <> path <> "?" <> URI.encode_query(query) @@ -394,7 +394,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.S3 do defp region_from_uri(uri) do # For many services the API host is of the form *.[region].[rootdomain].com - %{host: host} = URI.new!(uri) + %{host: host} = URI.parse(uri) host |> String.split(".") |> Enum.reverse() |> Enum.at(2, "auto") end diff --git a/lib/livebook/utils.ex b/lib/livebook/utils.ex index 3d37ccd33..466a48187 100644 --- a/lib/livebook/utils.ex +++ b/lib/livebook/utils.ex @@ -167,10 +167,8 @@ defmodule Livebook.Utils do """ @spec valid_url?(String.t()) :: boolean() def valid_url?(url) do - case URI.new(url) do - {:ok, uri} -> uri.scheme != nil and uri.host != nil - _ -> false - end + uri = URI.parse(url) + uri.scheme != nil and uri.host != nil end @doc """ @@ -247,7 +245,7 @@ defmodule Livebook.Utils do @spec expand_url(String.t(), String.t()) :: String.t() def expand_url(url, relative_path) do url - |> URI.new!() + |> URI.parse() |> Map.update!(:path, fn path -> path |> Path.dirname() |> Path.join(relative_path) |> Path.expand() end)