livebook/lib/livebook_cli
Wojtek Mach 453eabb6d4
Fix urls on Elixir master (#647)
Before Elixir master, empty path is represented as `nil`:

    ~% asdf shell elixir 1.12.3-otp-24 ; elixir -e 'IO.inspect URI.parse("http://localhost")'
    %URI{
      authority: "localhost",
      fragment: nil,
      host: "localhost",
      path: nil,
      port: 80,
      query: nil,
      scheme: "http",
      userinfo: nil
    }

On Elixir master, it is an empty string:

    ~% asdf shell elixir git ; elixir -e 'IO.inspect URI.parse("http://localhost")'
    %URI{
      authority: "localhost",
      fragment: nil,
      host: "localhost",
      path: "",
      port: 80,
      query: nil,
      scheme: "http",
      userinfo: nil
    }

The new default, the empty string, caused a bug on this line:

    Map.update!(:path, &((&1 || "/") <> path))

because we never prepended the leading `/` and thus we ended up with
path `"health"`, not `"/health"`, which now on Elixir master crashes:

    iex> URI.parse("http://localhost") |> Map.replace!(:path, "health") |> to_string()
    ** (ArgumentError) :path in URI must be empty or an absolute path if URL has a :host, got: %URI{authority: "localhost", fragment: nil, host: "localhost", path: "health", port: 80, query: nil, scheme: "http", userinfo: nil}
        (elixir 1.13.0-dev) lib/uri.ex:863: String.Chars.URI.to_string/1
2021-10-26 16:48:17 +02:00
..
server.ex Fix urls on Elixir master (#647) 2021-10-26 16:48:17 +02:00
task.ex Introduce token auth and add basic cli configuration (#148) 2021-04-08 11:41:52 +02:00