Skip to content

Commit beb10da

Browse files
wojtekmachjonatanklosko
authored andcommitted
Merge pull request from GHSA-564w-97r7-c6p9
1 parent 8f971ce commit beb10da

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

lib/livebook/utils.ex

+27-3
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@ defmodule Livebook.Utils do
307307
"data:#{mime};base64,#{data}"
308308
end
309309

310+
@doc """
311+
Expands URL received from the Desktop App for opening in the browser.
312+
"""
313+
def expand_desktop_url("") do
314+
LivebookWeb.Endpoint.access_url()
315+
end
316+
317+
def expand_desktop_url("/settings") do
318+
to_string(%{LivebookWeb.Endpoint.access_struct_url() | path: "/settings"})
319+
end
320+
321+
def expand_desktop_url("file://" <> path) do
322+
notebook_open_url(path)
323+
end
324+
325+
def expand_desktop_url("livebook://" <> rest) do
326+
notebook_import_url("https://#{rest}")
327+
end
328+
310329
@doc """
311330
Opens the given `url` in the browser.
312331
"""
@@ -323,10 +342,15 @@ defmodule Livebook.Utils do
323342

324343
{:unix, _} ->
325344
cond do
326-
System.find_executable("xdg-open") -> {"xdg-open", [url]}
345+
System.find_executable("xdg-open") ->
346+
{"xdg-open", [url]}
347+
327348
# When inside WSL
328-
System.find_executable("cmd.exe") -> {"cmd.exe", win_cmd_args}
329-
true -> nil
349+
System.find_executable("cmd.exe") ->
350+
{"cmd.exe", win_cmd_args}
351+
352+
true ->
353+
nil
330354
end
331355
end
332356

lib/livebook_app.ex

+4-27
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ if Mix.target() == :app do
1818

1919
@impl true
2020
def handle_info({:event, "open", url}, state) do
21-
open(url)
21+
url
22+
|> Livebook.Utils.expand_desktop_url()
23+
|> Livebook.Utils.browser_open()
24+
2225
{:noreply, state}
2326
end
2427

@@ -27,31 +30,5 @@ if Mix.target() == :app do
2730
Livebook.Config.shutdown()
2831
{:noreply, state}
2932
end
30-
31-
defp open("") do
32-
open(LivebookWeb.Endpoint.access_url())
33-
end
34-
35-
defp open("file://" <> path) do
36-
path
37-
|> Livebook.Utils.notebook_open_url()
38-
|> open()
39-
end
40-
41-
defp open("livebook://" <> rest) do
42-
"https://#{rest}"
43-
|> Livebook.Utils.notebook_import_url()
44-
|> open()
45-
end
46-
47-
defp open("/settings") do
48-
%{LivebookWeb.Endpoint.access_struct_url() | path: "/settings"}
49-
|> to_string()
50-
|> open()
51-
end
52-
53-
defp open(url) do
54-
Livebook.Utils.browser_open(url)
55-
end
5633
end
5734
end

0 commit comments

Comments
 (0)