From 465d7113959bd9dd8b9f0c5821e0b4d3068fff4f Mon Sep 17 00:00:00 2001 From: Cocoa Date: Wed, 12 Feb 2025 16:10:24 +0100 Subject: [PATCH] fix: path should be URL-encoded in Elixir code (#2926) Signed-off-by: Cocoa Co-authored-by: Wojtek Mach --- rel/app/macos/Sources/Livebook/Livebook.swift | 2 +- rel/app/windows/Livebook.cs | 3 +-- test/livebook/utils_test.exs | 6 ++++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rel/app/macos/Sources/Livebook/Livebook.swift b/rel/app/macos/Sources/Livebook/Livebook.swift index f516bcdff..1a03edf6e 100644 --- a/rel/app/macos/Sources/Livebook/Livebook.swift +++ b/rel/app/macos/Sources/Livebook/Livebook.swift @@ -110,7 +110,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } for url in urls { - ElixirKit.API.publish("open", url.absoluteString) + ElixirKit.API.publish("open", "file://\(url.path)") } } diff --git a/rel/app/windows/Livebook.cs b/rel/app/windows/Livebook.cs index 0172fe46c..0f32df8de 100644 --- a/rel/app/windows/Livebook.cs +++ b/rel/app/windows/Livebook.cs @@ -18,8 +18,7 @@ static class LivebookMain if (args.Length == 1 && args[0].StartsWith(prefix)) { - var uri = new System.Uri(args[0].Remove(0, prefix.Length)); - url = uri.AbsoluteUri; + url = $"file://{args[0].Remove(0, prefix.Length)}"; } var logPath = getLogPath(); diff --git a/test/livebook/utils_test.exs b/test/livebook/utils_test.exs index 4723bed6e..c239ac384 100644 --- a/test/livebook/utils_test.exs +++ b/test/livebook/utils_test.exs @@ -21,6 +21,12 @@ defmodule Livebook.UtilsTest do assert Livebook.Utils.expand_desktop_url("file://c\\foo.txt") == "http://localhost:4002/open?path=c%5Cfoo.txt" + + assert Livebook.Utils.expand_desktop_url("file:///this is a dir/with many spaces/foo.txt") == + "http://localhost:4002/open?path=%2Fthis+is+a+dir%2Fwith+many+spaces%2Ffoo.txt" + + assert Livebook.Utils.expand_desktop_url("file://\\\\127.0.0.1\\my folder\\foo.txt") == + "http://localhost:4002/open?path=%5C%5C127.0.0.1%5Cmy+folder%5Cfoo.txt" end test "livebook://" do