Revert to URI.parse/1 (#770)

This commit is contained in:
Jonatan Kłosko 2021-12-08 16:11:04 +01:00 committed by GitHub
parent c9b21f221d
commit fef322706f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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)