Fix attached runtime configuration string ambiguity with IPv6 (#459)

* Fix attached runtime configuration string ambiguity with IPv6

* Preserve the NODE:COOKIE order
This commit is contained in:
Jonatan Kłosko 2021-07-23 10:19:30 +02:00 committed by GitHub
parent 6575791bed
commit 756420f5fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -200,7 +200,7 @@ defmodule Livebook.Config do
end
defp parse_connection_config!(config) do
[node, cookie] = String.split(config, ":", parts: 2)
{node, cookie} = split_at_last_occurrence(config, ":")
unless node =~ "@" do
abort!(~s{expected node to include hostname, got: #{inspect(node)}})
@ -212,6 +212,15 @@ defmodule Livebook.Config do
{node, cookie}
end
defp split_at_last_occurrence(string, pattern) do
{idx, 1} = string |> :binary.matches(pattern) |> List.last()
{
binary_part(string, 0, idx),
binary_part(string, idx + 1, byte_size(string) - idx - 1)
}
end
@doc """
Aborts booting due to a configuration error.
"""